Issue
I get this error when starting a foreground service:
Java.Lang.RuntimeException: Bad notification for startForeground: java.lang.RuntimeException: invalid service notification: Notification(channel=channelSocketIOService pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x42 color=0x00000000 vis=PRIVATE)
--- End of managed Java.Lang.RuntimeException stack trace ---
android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid service notification: Notification(channel=channelSocketIOService pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x42 color=0x00000000 vis=PRIVATE)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1945)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
/end;
In service class:
private void RegisterForegroundService()
{
Notification notification = new NotificationCompat.Builder(this, $"ServiceNotifications")
.SetOngoing(true)
.Build();
StartForeground(462, notification);
}
Thanks for your help
Solution
Solution:
- Go to Android-Settings > Build
- Turn off code optimization
- Build the solution
- Turn code optimization back on
Worked for me but don't know why
Answered By - FireBird
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.