Hi ...
the built in notification lib, doesn't show an icon
I create a new project with this code
B4X:
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Dim n As Notification
n.Initialize
n.Icon = "icon"
n.SetInfo("test", "test", Me)
n.Notify(1)
End Sub
Background The notifications features changed a lot as Android evolved. Android 8 (with targetSdkVersion 26+) adds another complexity with the introduction of notification channels. The built-in Notification object was rewritten in B4A v8 to work properly with all versions. This is a good...
I tried it, but when i use Service.StartForeground with NB6 notification and test it on Galaxy A10 (9.0)
it gives me this error:
B4X:
** Receiver (timerservice) OnReceive **
*** Service (starter) Create ***
** Service (starter) Start **
** Service (timerservice) Create **
** Service (timerservice) Start **
Service started in foreground mode.
android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=null pri=1 contentView=null vibrate=null sound=null defaults=0xfffffffc flags=0x43 color=0x00000000 vis=PRIVATE semFlags=0x0 semPriority=0 semMissedCount=0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1915)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7258)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
Any help ??
if the icon appears the in built notification, that's will fix the problem, because the Service.StartForeground with built notification doesn't make any error
after some minutes the service stopped with this error
this happened just one time on Note4, on Galaxy 10 worked fine
B4X:
** Service (timerservice) Create **
** Service (timerservice) Start **
android.app.RemoteServiceException: Bad notification posted from package com.lutuf.SurvivalShip: Couldn't update icon: StatusBarIcon(icon=Icon(typ=RESOURCE pkg=com.lutuf.SurvivalShip 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)
NB6.Build returns a regular Notification object. You can pass it to Service.StartForeground. No need to set OnGoingEvent as all foreground notifications behave like that.
One other thing I found out is that some OS versions (ie. android 5.x) are very picky on the icon size and will just display a blank circle in it's notification if it's not right.