Android Question Service Bad notification startForeground

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Hello,
I create a service that works foreground.

B4X:
Sub Process_Globals
Dim sNotif As Notification
End Sub

Sub Service_Create
sNotif.Initialize
Service.StartForeground(1, sNotif)
End Sub

When I start the application, I've got this log error.
What's wrong?


B4X:
** Activity (main) Create, isFirst = true **


--Service Started--
** Service (sinventario) Start **

Start Service
** Activity (main) Pause, UserClosed = true **

android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: icon must be non-zero

    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488)
    at android.os.Handler.dispatchMessage(Handler.java:110)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:5292)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
    at dalvik.system.NativeStart.main(Native Method)
 

sonicmayne

Member
Licensed User
Longtime User
You have initialized the notification, but as the exception says you haven't set an icon for it.

If you just want to the use app's default icon use:
B4X:
sNotif.Iccon = "icon"

Also you haven't called SetInfo or SetInfo2, are you sure you want to display no text to the user?
 
Upvote 0

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
If it is possible, I don't want also to display the notification
 
Upvote 0

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
After I add:
B4X:
sNotif.SetInfo("", "", Main)
sNotif.Icon = "icon"

The app works.

Thanks
 
Upvote 0
Top