Recently wanted to show all audio files on sdcard and phone that are set as ring tone and get the path of the file and i learn't that we have to call RingtoneManager. ACTION _RINGTONE_ PICKER intent activity and after a loads of trial and errors on bits of pieces of sample codes found on internet i was finally able to make it work and i thought of sharing with you and as an archive for my future reference below is the sample code.
Call the ring tone picker activity as given below
String uri = null;
Intent intent = new Intent( RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra( RingtoneManager.EXTRA_RINGTONE_TYPE,
RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra( RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Tone");
if( uri != null)
{
intent.putExtra( RingtoneManager.EXTRA_RINGTONE_EXISTING_URI,
Uri.parse( uri));
}
else
{
intent.putExtra( RingtoneManager.EXTRA_RINGTONE_EXISTING_URI,
(Uri)null);
}
startActivityForResult( intent, Set_Ringtone);
Intent intent = new Intent( RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra( RingtoneManager.EXTRA_RINGTONE_TYPE,
RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra( RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Tone");
if( uri != null)
{
intent.putExtra( RingtoneManager.EXTRA_RINGTONE_EXISTING_URI,
Uri.parse( uri));
}
else
{
intent.putExtra( RingtoneManager.EXTRA_RINGTONE_EXISTING_URI,
(Uri)null);
}
startActivityForResult( intent, Set_Ringtone);
On onActivityResult use the below code to get the path
if (resultCode == RESULT_OK) {
Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
if (uri != null) {
String ringTonePath = uri.toString();
}
}
Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
if (uri != null) {
String ringTonePath = uri.toString();
}
}
and between remember if you pick or select "Silent" you will get "null" in URI as path the above code worked well for me if you have any problem or getting error feel free to contact me by leaving email by clicking icon at the bottom of this page
15 comments:
Thank you very much. I'll give it a try
Works nicely, thanks mucho!
Nice example...
In the above code always silent is shown as checked though we selected another ringtone can any one solve that problem.
Hi...
Above code is working nicely,but how to show music files or ringtones that are available in sd card into ringtone picker.Can any one solve this?
this is worked but problem is ringTonePath is always null.
I'm having the same problem as Dipak, is there a related permission we need to get useful data back?
This returns the id inside the RingtoneManager Database not actual file path..
I play sound via Soundpool (file path needed).
Any way i can get this path?
Great stuff...
All works great but i am trying to change the default sound with what has been returned
For example
RingtoneManager.setActualDefaultRingtoneUri(getApplicationContext(), RingtoneManager.TYPE_RINGTONE, soundUri);
Everywhere i look it says this is correct.. Am i doing something wrong?
Thanks alot!
Works like a charm :)
Thank you. very useful
Chaim
" content://settings/system/ringtone "
getting this as a same path for all the ringtone ?
is it right ? will it work ?
i mean how come it has same path for different ringtone ?
thanks sir
how to save picked ringtone?
if i have select the silent tone error will occur why?
where does this come from?
Set_Ringtone
in the line:
startActivityForResult( intent, Set_Ringtone);
Post a Comment