Android Question built in notification, no icon

Fadi-l

Member
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

the result:
image.jpg


no icon in the circle

test project attached

I tried it on Android 6.1 (note 4)

What should I do ?

Thank you ....
 

Attachments

  • test.zip
    406.2 KB · Views: 133

JohnC

Expert
Licensed User
Longtime User
Try using the NB6 lib:

 
Upvote 0

Fadi-l

Member
thank you JohnC for the reply

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)
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Are you getting this error with the example or your own code?

The NB6 uses this new thing called "Channels" for the notifications and it seems like the error is related to this.
 
Upvote 0

Fadi-l

Member
this code:

B4X:
    Dim n As NotificationBuilder
    n.Initialize
    n.Priority = 1
    n.SmallIcon = "icon"
    n.OnGoingEvent = True
    n.AutoCancel = False
    n.DefaultSound = False
    n.DefaultVibrate = False
    n.ContentTitle = Application.LabelName
    n.ContentText = "test ..."
    n.setActivity(Main)
    n.Notify(100)
    Service.StartForeground(100, n.GetNotification)
B4X:

is there a problem in my code ?
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Test the example first, and if it works, then find the difference between your code and the example.
 
Upvote 0

Fadi-l

Member
Test the example first, and if it works, then find the difference between your code and the example.

Same problem ...

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
 
Upvote 0

Fadi-l

Member
I tried NB6 Class

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)

I replaced this code :
B4X:
    n.Initialize2(notification.IMPORTANCE_LOW)
    n.Icon = "icon"
    n.OnGoingEvent = True
    n.Light   = False
    n.Vibrate = False
    n.Sound = False
    n.SetInfo(title, value, Main)
    n.Notify(100)
    Service.StartForeground(100, n)

With this one:
B4X:
    Private icon As Bitmap
    icon = LoadBitmapResize(File.DirAssets, "notification_icon.png", 24dip, 24dip, False)
    Dim n As NB6
    n.Initialize("default", Application.LabelName, "LOW").AutoCancel(False).SmallIcon(icon)
    n.Build(title, value, "", Main).Notify(100)


But how to use
Service.StartForeground(100, n) and n.OnGoingEvent = True
with NB6 ?
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This thread is becoming too messed up to be useful.

But how to use
Service.StartForeground(100, n) and n.OnGoingEvent = True
with NB6 ?
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.

For further discussion please start a new thread.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
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.

I found 62 x 62 x 32 worked best for me.
 
Upvote 0
Top