Android Question How to convert a sbn.notification to save do a database (as string?) and revert it back to a notification

Chicao99

Member
Licensed User
Longtime User
I've tried below code but it didn't work, the program is treating the newnotif variable as a string, any ideas?

B4X:
        Dim jsongen As JSONGenerator
        jsongen.Initialize(CreateMap("data":SBN.Notification))
        Dim jsonstr As String = jsongen.ToString
                
        Dim jp As JSONParser
        jp.Initialize(jsonstr)
        
        Dim pmap As Map = jp.NextObject
        
        Dim newnotif As Notification = pmap.Get("data")
 

Chicao99

Member
Licensed User
Longtime User
I'm getting this error when trying to use the notification:

java.lang.ClassCastException: java.lang.String cannot be cast to android.app.Notification
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Not sure what is SBN.
If you are using FirebaseNotifications library, then part of the code is as follow:
B4X:
Sub fm_MessageArrived (Message As RemoteMessage)
    Log("Message arrived")
    Log($"Message data: ${Message.GetData}"$)
    Dim n2 As Notification
    n2.Initialize2(n2.IMPORTANCE_DEFAULT)
    n2.Icon = "icon"
    n2.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body"), Main)
    n2.Notify(1) 
End Sub
Check the details here:
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Are you referring to StatusBarNotification?

Maybe this thread helps:
 
Upvote 0
Top