Android Question (SOLVED) Default Ringtone Uri

Traiser

Member
Licensed User
Longtime User
Hi all, i have one problem with this code:

B4X:
Dim uri As String
uri = rm.GetDefault(rm.TYPE_RINGTONE)

In this code the uri is : "content://settings/system/ringtone" but for default ringtone i need a uri like this "content://media/internal/audio/media/81"

can you help me?
thanks!

sorry for my english :)
 

Traiser

Member
Licensed User
Longtime User
You should be able to play this uri with MediaPlayer, have you tried it?
yes but a need a uri like this for save the current uri ringtone in the sql database for next recall when the ringtone is changed.
if i save this uri "content://settings/system/ringtone" when the ringtone is changed can i set old ringtone with this uri?

sorry for my english :)
 
Upvote 0

Traiser

Member
Licensed User
Longtime User
I found this java code on the internet
B4X:
String defaultPath = Settings.System.DEFAULT_RINGTONE_URI.getPath();
with this code can i somehow resolve my problem?

thanks for all replies! :)
 
Upvote 0

Traiser

Member
Licensed User
Longtime User
ok but maybe i found something..
java code for under api level 18:
B4X:
 Uri DefaultRingtoneUri = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE);

if (DefaultRingtoneUri != null) {
  Cursor c = getContentResolver().query(DefaultRingtoneUri, null, null, null, null);
  c.moveToFirst();
  BellName = c.getString(c.getColumnIndex(MediaStore.MediaColumns.TITLE));
  mediaURI = String.valueOf(DefaultRingtoneUri);
}

and java code for 4.4 kitkat:
B4X:
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
is this a useful code for get default uri?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The first code snippets looks good:
B4X:
Dim jo As JavaObject
jo.InitializeStatic("android.media.RingtoneManager")
Dim context As JavaObject = Activity
context = context.RunMethod("getContext", Null)
Log(jo.RunMethod("getActualDefaultRingtoneUri", Array As Object(context, 1)))
 
Upvote 0

Traiser

Member
Licensed User
Longtime User
The first code snippets looks good:
B4X:
Dim jo As JavaObject
jo.InitializeStatic("android.media.RingtoneManager")
Dim context As JavaObject = Activity
context = context.RunMethod("getContext", Null)
Log(jo.RunMethod("getActualDefaultRingtoneUri", Array As Object(context, 1)))

this snippets code is perfect, Great Work!
Thanks for Your help! :)
 
Upvote 0
Top