How to get the ringtone name (not number)

drachmad

Member
Licensed User
Longtime User
I use:
Dim rm as RingtoneManager
rm.ShowRingtonePicker("rm", rm.TYPE_RINGTONE, True, "")
rm_PickerResult (Success As Boolean, Uri As String)

It shows the ringtone names but ...
The return value URI give only the directory and ringtone NUMBER and NOT the name of the ringtone.

Thanks for any help.
 

stevel05

Expert
Licensed User
Longtime User
I came across this on Stack exchange.

You need the Uri from RingtoneManager and reflection to get the name, as you don't want the Default ringtone (as in the link) we need to use the Uri returned from the picker:

B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

   Dim RM As RingtoneManager
End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")

   RM.ShowRingtonePicker("RM",RM.TYPE_RINGTONE,True,"")

End Sub
Sub RM_PickerResult (Success As Boolean, Uri As String)

   If Success Then
      Dim R As Reflector
      'Convert the selected Uri string to a Uri Object compatible with the getRingtone method.
      Dim RTUri As Object = R.RunStaticMethod("android.net.Uri","parse",Array As Object(Uri),Array As String("java.lang.String"))
      'Get the actual ringtone object from the Uri
      R.Target = R.RunStaticMethod("android.media.RingtoneManager","getRingtone",Array As Object(R.GetContext,RTUri),Array As String("android.content.Context","android.net.Uri"))
      'Get the title from the ringtone object
      Dim Name As String = r.RunPublicmethod("getTitle",Array As Object(R.GetContext),Array As String("android.content.Context"))
      'Silent returns Unknown ringtone
      Log("RingToneName="&Name)
   Else
      Log("Pickerresult Error")
   End If
   
End Sub
 
Last edited:
Upvote 0
Top