How to get ringtone path in android

351 Views Asked by At

Whether exists way to get direct path to some ringtone uri,which we can get via ringtoneManager,which will works for all apis. I need in direct file path to play it on media player without looping. Have anybody ideas,how to get absolute path of any ringtone? Thanks everybody for any help.

1

There are 1 best solutions below

2
Urvish Shiroya On

I was struggling with this issue as well, And i found solution that i explain you how i get atual ringtone in Android.

NOTE: but you need those permission first.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Uri defaultRingtoneUri = RingtoneManager.getActualDefaultRingtoneUri(getActivity().getApplicationContext(), RingtoneManager.TYPE_RINGTONE);
Ringtone defaultRingtone = RingtoneManager.getRingtone(getActivity(), defaultRingtoneUri);

OR

You need to got all default ringtones in android with path. then you can use this code in android.

RingtoneManager ringtoneManager = new RingtoneManager(this);
ringtoneManager.setType(RingtoneManager.TYPE_RINGTONE);
Cursor cursor = ringtoneManager.getCursor();
while (cursor.moveToNext()) {
    Log.e("RINGTONE", "NAME: " + cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX));
    Log.e("RINGTONE", "PATH: " + cursor.getString(RingtoneManager.URI_COLUMN_INDEX));
}