In my program, I want to save a selected ringtone by it’s file path, and then set it as the current ringtone later.
I have got the ringtone uri from RingtonePreference, and get the file path of it from MediaStore database.
e.g.
Uri - content://media/internal/audio/media/29 Path - /system/media/audio/notifications/Ascend.mp3
Now, how to I get the ringtone Uri from the file path i saved ?
Since the ringtone already exist in MediaStore, I tried the following functions, but it’s not working.
uriRingtone = MediaStore.Audio.Media.getContentUriForPath(szRingtonePath);
The Uri is not the same as the one I got from RingtonePreference.
uriRingtone - content://media/internal/audio/media
How do I query the MediaStore to get the Uri I need?
p.s. the reason that I don’t store the ringtone Uri directly is that I found the Uri for the same ringtone might change sometimes in some device.
The way you can recover the ringtone URI stored in the RingtonePreference is (as far as I know) by knowing the title of the song. Then you can query it by using a cursor to obtain the ringtone _id stored and with it you can build an URI:
where finalSuccessful uri is the uri pointing to the ringtone in the RingtonePreference.