question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RemoteServiceException: Bad notification for startForeground crash on >= Android 8.1

See original GitHub issue

There is an issue related to the updates in Android system, Since Android 8.1 you need to create own notification channel for foreground service

So in DfuBaseService in startForeground method you need to add something like this:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_DFU, "Update service",NotificationManager.IMPORTANCE_NONE); chan.setLightColor(Color.BLUE); chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); NotificationManager service = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); service.createNotificationChannel(chan); }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
AndroidDeveloperLBcommented, Feb 23, 2022
1reaction
chris-guidrycommented, Aug 13, 2019

@philips77 I am experiencing the same issue, which crashes our app whenever we try to run a DFU.

Here is the error:

FATAL EXCEPTION: main
android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=dfu pri=-1 contentView=null vibrate=null sound=null defaults=0x0 flags=0x42 color=0xff888888 number=0 vis=PRIVATE semFlags=0x0 semPriority=0 semMissedCount=0)
 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1906)
 	at android.os.Handler.dispatchMessage(Handler.java:106)
 	at android.os.Looper.loop(Looper.java:164)
 	at android.app.ActivityThread.main(ActivityThread.java:7000)
 	at java.lang.reflect.Method.invoke(Native Method)
 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)

Based on the Stack Overflow post, “startForeground fail after upgrade to Android 8.1”, and the research by @krtkv, it seems the function startForeground in DfuBaseService.java should be updated to include the NotificationChannel. I could work on changing it, but I don’t have a great way to test the changes before creating a pull request. Is that something you are able to change/test/push/version? If so, it would be much appreciated!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bad notification for startForeground (Android 8.1+) - B4X
Service Starter Start android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel ...
Read more >
android.app.RemoteServiceException: Bad notification for ...
But I got the error below on Android 8.1, 9.0 and 10.0 Emulator. android.app.RemoteServiceException: Bad notification for startForeground: java.
Read more >
Android – Bad notification for start Foreground, Invalid ...
The problem i am having is these logs don't provide any log from where i can see the source in my app that...
Read more >
Startup Crash on Android 8.1 (#1124) · Issues - briar
RemoteServiceException : Bad notification for startForeground: java.lang ... Crash on Android 8.1 to Startup Crash on Android 8.1 4 years ago.
Read more >
android 8.1 invalid channel for service notification
RemoteServiceException : Bad notification for startForeground: java.lang. ... 大于26时,这个channel需要进行系统注册,否则会crash,crash信息如下:android.app.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found