Hi all, I have some code to select a ringtone and then use it in a notification using NB6
I save the URI as a string
now I would like to use this string for the n.CustomSound of NB6
can someone help me ?
Thank's.
B4X:
Sub btnoti_Click
RM.ShowRingtonePicker("RM",RM.TYPE_ALARM,False,btnoti.Tag)
End Sub
Sub RM_PickerResult (Success As Boolean, Uri As String)
Log("success..." & Success)
Log("Uri : " & Uri)
If Success Then
Dim name As String
name = ringname(Uri)
btnoti.Tag = Uri
lblnotiring.Text = name
' Log("Uri :" & Uri)
' Log("RingToneName="&name)
Else
Log("Pickerresult Error")
End If
End Sub
Private Sub ringname(Uri As String) As String
Try
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
Return Name
Catch
Log("ERRORE NOTIFICA :" & LastException.Message)
' ToastMessageShow("Errore :" & LastException.Message,False)
End Try
Return "default"
End Sub
I save the URI as a string
now I would like to use this string for the n.CustomSound of NB6
B4X:
Dim n As NB6
n.Initialize("Prova Notifica", Application.LabelName, "HIGH")
n.SmallIcon(LoadBitmapResize(File.DirAssets, "icon.png", 32dip, 32dip, True))
'disable the default sound
n.SetDefaults(False, True, True)
'set custom sound
n.CustomSound(btnoti.Tag) <---- This is a string of uri but n.CustomSound expect Fileprovider Uri object..
Dim Notification As Notification = n.Build("Allarme " & riga1, riga2, "", Main)
Notification.Notify(2)
can someone help me ?
Thank's.