Android Question Notification builder problem

jayel

Active Member
Licensed User
Longtime User
Hello,

My code :
B4X:
Sub fm_MessageArrived (Message As RemoteMessage)


       'Try
        Log("Message arrived")
        Log($"Message data: ${Message.GetData}"$)

        Dim nb As NotificationBuilder
        ' Dim nbBigTextStyle As NotificationBigTextStyle
        Dim title As String = Message.GetData.get("title")
        'Log("title 2de karakter : " & title.SubString2(1,2))
        Dim body As String = Message.GetData.Get("body")
        Dim soort As Char = title.SubString2(0,1)
        Dim severity As Int = title.SubString2(1,2)
        Dim acttitle As String = title.SubString(2)
        nb.Initialize
    
        Select Case soort
            Case "D"
                nb.SmallIcon = "ic_home_variant_white_24dp"
            Case "A"
                nb.SmallIcon = "ic_bell_white_24dp"
            Case "P"
                nb.SmallIcon = "ic_gate_white_24dp"
            Case "K"
                nb.SmallIcon = "ic_panda_white_24dp"
            Case Else
                nb.SmallIcon = "icon"
         
        End Select
        nb.Ticker = "Robonotification"
        nb.setActivity("modnotificatiesoort")
        nb.ContentTitle = acttitle
        nb.DefaultLight = True
        nb.DefaultVibrate = False
        nb.DefaultSound = False
        Dim passSound As Boolean = False
        Dim welk As Int
        Select Case soort
            Case "P"
                welk = 0
                Dim myfullname As String = Starter.pubuser.voornaam & " " & Starter.pubuser.naam
                Dim searchbody As String = body.ToLowerCase
                If searchbody.Contains(myfullname.ToLowerCase) = True Then
                    passSound = True
                    Log("pass")
                    nb.CustomSound = "file:///sdcard/Notifications/pass.mp3"
                
                End If
            Case "D"
                welk = 1
            Case "A"
                welk = 2
            Case "K"
                welk = 3
        End Select
        Log(passSound)
        If passSound = False Then
            Select Case severity
                Case 0
                    nb.CustomSound = ""
                Case 1
                    nb.CustomSound = "file:///sdcard/Notifications/beep.mp3"
                Case 2
                    nb.CustomSound = "file:///sdcard/Notifications/beep2.mp3"
                Case 3
                    nb.CustomSound = "file:///sdcard/Notifications/beep3.mp3"
                Case 4
                    nb.CustomSound = "file:///sdcard/Notifications/beep4.mp3"
                Case 5
                    nb.CustomSound = "file:///sdcard/Notifications/beep5.mp3"
                Case Else
                    nb.CustomSound = "file:///sdcard/Notifications/beep.mp3"
            End Select
        End If

    
    
        Dim mynotification As notificationsoort
        Dim n As Int
        For Each mynotif As notificationsoort In Starter.lstNotifications
        If mynotif.soort = soort Then
            mynotification = mynotif
        
            Exit
        End If
        Next
        Dim returnvalue As Int = InsertNotification(acttitle,Message.GetData.Get("body"), soort,Message.GetData.Get("bodydetail") )
        mynotification.nr = mynotification.nr + 1
        nb.ContentText =  Message.GetData.Get("body")
        Log("Body detail : " & Message.GetData.Get("bodydetail") )
        nb.Number = returnvalue 'mynotification.nr 'Starter.notificationNr
        nb.Autocancel = True
        nb.tag = soort
        nb.Notify(welk) 'myid
    
    
    
    'Catch
    '    Log(LastException)
    'End Try


End Sub

When a firebase message arrives I got to analyse it and make a notification with notification builder.
I have a strange problem: the customsound "pass.mp3" will not play, even when it should.
When I put a breakpoint and step into the code the sound plays ???

Somebody?

John
 

An Schi

Well-Known Member
Licensed User
Are you sending the push via firebase console or http request?
The console has limitations on showing notifications...
 
Upvote 0

jayel

Active Member
Licensed User
Longtime User
Firebase, the notification side does work because the notification send by firebase is saved in a sqlite databse
 
Upvote 0

An Schi

Well-Known Member
Licensed User
The answer is right above (and on other threads): the console has limitations on showing notifications - use erels B4J code to send and you will get the notification.
 
Upvote 0

jayel

Active Member
Licensed User
Longtime User
An shi,

I AM using erels code to send the message, it is not via the console.
I receive the messages, that is not the problem, but the notification builder doen't play the sound (
file:///sdcard/Notifications/pass.mp3)
 
Upvote 0

jayel

Active Member
Licensed User
Longtime User
That seems to solved my problem !
Thanks to all !

PS this is a great community !
 
Upvote 0

panagiotisden2

Active Member
Licensed User
Longtime User
here is my way to solve this
B4X:
If File.Exists("/sdcard/Notifications/","ding.mp3")=False Then
    File.MakeDir("/sdcard/","Notifications")
    File.Copy(File.DirAssets,"ding.mp3","/sdcard/Notifications/","ding.mp3")
 
Upvote 0
Top