Accessing Ringtones

Put your problem here if it does not fit any of the other categories.

Accessing Ringtones

Postby Yellowdog » Sun May 02, 2010 6:55 am

Need a little help accessing ringtones on the phone.

Basically I want to get all of the ringtones on the phone and put them in a spinner, then play the ringtone.

The only thing I can find on spinners is using an array to fill it, and I can't access the ringtones anyway.

I was going to use MediaPlayer to play the ringtones so not worried about that.

Any help would be great!
Yellowdog
Junior Developer
Junior Developer
 
Posts: 20
Joined: Thu Apr 22, 2010 6:37 am

Top

Postby Yellowdog » Sun May 02, 2010 5:44 pm

Ok, I found this snipit, and is setting the default ringtone for the phone, but what I am looking for is the ability to select a ringtone and play it when a button is pressed.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package com.mine;
  3.  
  4.  
  5.  
  6. import android.app.Activity;
  7.  
  8. import android.content.ContentUris;
  9.  
  10. import android.content.Intent;
  11.  
  12. import android.media.RingtoneManager;
  13.  
  14. import android.net.Uri;
  15.  
  16. import android.os.Bundle;
  17.  
  18. import android.provider.MediaStore;
  19.  
  20. import android.util.Log;
  21.  
  22. import android.view.View;
  23.  
  24. import android.view.View.OnClickListener;
  25.  
  26. import android.widget.TextView;
  27.  
  28.  
  29.  
  30. public class Sample extends Activity implements OnClickListener {
  31.  
  32.         /** Called when the activity is first created. */
  33.  
  34.         private TextView textView;
  35.  
  36.  
  37.  
  38.         @Override
  39.  
  40.         public void onCreate(Bundle savedInstanceState) {
  41.  
  42.                 super.onCreate(savedInstanceState);
  43.  
  44.                 setContentView(R.layout.main);
  45.  
  46.                 textView = (TextView) findViewById(R.id.sample);
  47.  
  48.                 textView.setOnClickListener(this);
  49.  
  50.         }
  51.  
  52.  
  53.  
  54.         @Override
  55.  
  56.         public void onClick(View v) {
  57.  
  58.                 Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
  59.  
  60.                 intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE,
  61.  
  62.                                 "My customised Title");
  63.  
  64.                 Uri uri = ContentUris.withAppendedId(
  65.  
  66.                                 MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, 1l);
  67.  
  68.                 // Don't show 'Silent'
  69.  
  70.                 intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
  71.  
  72.  
  73.  
  74.                 intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, uri);
  75.  
  76.                 startActivityForResult(intent, 123);
  77.  
  78.  
  79.  
  80.         }
  81.  
  82.  
  83.  
  84.         @Override
  85.  
  86.         protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  87.  
  88.                 switch (resultCode) {
  89.  
  90.                 /*
  91.  
  92.                  * case RESULT_OK: this.setResult(RESULT_OK); this.finish(); break;
  93.  
  94.                  */
  95.  
  96.  
  97.  
  98.                 case RESULT_OK:
  99.  
  100.                         Uri uri = data
  101.  
  102.                                         .getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
  103.  
  104.                         Log.i("Sample", "uri " + uri);
  105.  
  106.                         RingtoneManager.setActualDefaultRingtoneUri(this,
  107.  
  108.                                         RingtoneManager.TYPE_RINGTONE, uri);
  109.  
  110.                         break;
  111.  
  112.                 }
  113.  
  114.         }
  115.  
  116. }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


Any help on modifying this code to do what I need would be appreciated
Thanks!
Yellowdog
Junior Developer
Junior Developer
 
Posts: 20
Joined: Thu Apr 22, 2010 6:37 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google Adsense [Bot] and 17 guests