When I pick the default ringtone, I get a Uri
with path content://settings/system/ringtone
. So there is no path ending with integer, as in returning a usual rintone (for example, content://media/internal/audio/media/38
).
How can I now get a resource id from this default ringtone? Any parsing is impossible since there is no any integer identification.
If your check the setting db, you will find the content save to setting db is media uri. That means below uri actually is a map to media uri.
From:
content://settings/system/ringtone
To:
content://media/internal/audio/media/38
So you need to write a converter to do it:
public Uri uriMap(Uri uri) {
Uri mediaUri = uri;
if(uri.getAuthority().equals(Settings.AUTHORITY)) {
Cursor c = null;
try {
c = getContentResolver().query(uri,new String[]{
Settings.NameValueTable.VALUE},null,null,null);
if(c != null && c.moveToFirst()) {
String val = c.getString(0);
mediaUri = Uri.parse(val);
}
} catch (Exception e) {
}finally {
c.close();
}
}
Log.e(TAG,"" + uri + "->" + mediaUri);
return mediaUri;
}