Italian Problema con suonerie

CiccioU23

Member
B4X:
Sub rm_PickerResult (Success As Boolean, Uri As String)
    'Qui si scatena l'evento quando seleziono la suoneria , quello che a noi interessa è l'uri da poter utilizzare o memorizzare in una variabile nella shared preferences.
    If Success Then
        If Uri = "" Then
            ToastMessageShow("Silenzioso", True)
        Else
            mp.Load(rm.GetContentDir, Uri)
            mp.Play
        End If
        ToastMessageShow("Suoneria Selezionata", True)
    Else
        ToastMessageShow("Errore nel caricamento delle suonerie.", True)
    End If
    'Passa la suoneria selezionata al servizio, che la imposta nella proprietà CustomSound
    Notifica.Notifica.CustomSound=Uri
End Sub
Questo codice mi mostra una InputList delle suonerie di tipo NOTIFICATION, posso usare "Uri", che è la directory della suoneria selezionata, ma vorrei stampare il nome della suoneria, non la sua directory.
Avreste qualche idea?
 

iz0ndg

Member
Licensed User
Io utilizzo queste routine in un mio programma:
B4X:
Sub Process_Globals
  Dim RM As RingtoneManager
End Sub

Sub Globals
  Private btnoti As Button
End Sub

Sub btnoti_Click
'   Dim uri As String
'   uri = RM.GetDefault(RM.TYPE_NOTIFICATION)
'   uri = "content://settings/system/notification_sound"
  RM.ShowRingtonePicker("RM",RM.TYPE_NOTIFICATION,False,btnoti.Tag)
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
       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
 
Top