Android Question Remote notification error

marcick

Well-Known Member
Licensed User
Longtime User
I have this code to show a notification

B4X:
            Dim iconcar As Bitmap=LoadBitmapResize(File.DirAssets, "classictruck32blue.png", 24dip, 24dip, False)
            Dim nb As NB6
            nb.Initialize("default", Application.LabelName, "LOW").AutoCancel(True).SmallIcon(iconcar)    'low importance = no sound.
            nb.SetDefaults(False, False,False)
            nb.Build(n, m.Get("body"), "tag1", Main).Notify(1)

But sometimes (on a Galaxy Note 8) I have this error

B4X:
** Receiver (firebasemessaging) OnReceive **
** Service (firebasemessaging) Start **
android.app.RemoteServiceException: Bad notification posted from package xxx: Couldn't update icon: StatusBarIcon(icon=Icon(typ=RESOURCE pkg=xxx id=0x00000000) visible user=0 )
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2019)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:158)
    at android.app.ActivityThread.main(ActivityThread.java:7225)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)


Any idea ?
 

marcick

Well-Known Member
Licensed User
Longtime User
Which version of Android is running?

Do multiple messages arrive at once?
Should be 6.0 (note4, not note8)
I don't think multiple messages arrive together, but maybe a new message arrive when the previous notification has not been cleared.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Ok, the problem is just when a new message arrive when the previous notification has not been cleared.
I see now that this has already been discussed in the NB6 class Thread.

I tried to apply both the suggested solutions and both seems to work.

1) clear the notification before generating a new one

B4X:
    Dim nn As Notification       
    nn.Initialize
    nn.Cancel(2)
    Sleep(100)

2) modificating this sub in the NB6 class

B4X:
Private Sub CreateIconFromBitmap(bmp As Bitmap) As Object
    If bmp = Null Or bmp.IsInitialized = False Then Return 0
    Dim icon As JavaObject
    'Return icon.InitializeStatic("android.graphics.drawable.Icon").RunMethod("createWithBitmap", Array(bmp))
    Dim xml As XmlLayoutBuilder
    Return icon.InitializeStatic("android.graphics.drawable.Icon").RunMethod("createWithResource", Array(ctxt,xml.GetResourceId("drawable","icon")))
End Sub

Any suggestion what is better ?
 
Upvote 0
Top