Android Question RingtoneManager & NB6

Discussion in 'Android Questions' started by iz0ndg, May 28, 2018.

  1. iz0ndg

    iz0ndg Member Licensed User

    Hi all, I have some code to select a ringtone and then use it in a notification using NB6
    Code:
    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 StringAs 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

    Code:
    Dim n As NB6
       n.Initialize(
    "Prova Notifica"Application.LabelName, "HIGH")
       n.SmallIcon(LoadBitmapResize(
    File.DirAssets, "icon.png"32dip32dipTrue))
       
    'disable the default sound
       n.SetDefaults(FalseTrueTrue)
       
    '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.
     
  2. DonManfred

    DonManfred Expert Licensed User

  3. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    Sub Notification_WithCustomSound
       
    Dim n As NB6
       n.Initialize(
    "custom sound3"Application.LabelName, "DEFAULT")
       n.SmallIcon(LoadBitmapResize(
    File.DirAssets, "smiley.png"32dip32dipTrue))
       
    'disable the default sound
       n.SetDefaults(FalseTrueTrue)
       
    'set custom sound
       Dim rm As RingtoneManager 'Phone library
       Sleep(210'allow the list to finish the "click animation"
       rm.ShowRingtonePicker("rm", rm.TYPE_RINGTONE, False"")
       
    Wait For rm_PickerResult (Success As Boolean, UriString As String)
       
    If Success Then
           
    Dim Uri As Uri 'ContentResolver library
           Uri.Parse(UriString)
           n.CustomSound(
    Uri)
       
    End If
       
    Dim Notification As Notification = n.Build("Notification with custom sound""...""", Me)
       
    Notification.Notify(3)
    End Sub
    Note that you will need to change the channel id each time that you change the sound. It can be confusing. If it doesn't work then change the id (custom sound3 in the above code).
     
    lte5000, Johan Hormaza and iz0ndg like this.
  4. iz0ndg

    iz0ndg Member Licensed User

    Thank you Erel...;)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice