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.

Bad notification for startForeground

See original GitHub issue

On Huawei P20 Pro With Android 8.1.0 I had to disable startForeground in order to let nordic dfu updater works, otherwise app crashes with this error:

05-24 16:09:08.024 12022-12022/bike.woolf.woolfupdater E/AndroidRuntime: FATAL EXCEPTION: main
                                                                         Process: com.example.dfuupdater, PID: 12022
                                                                         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 vis=PRIVATE)
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2095)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:109)
                                                                             at android.os.Looper.loop(Looper.java:166)
                                                                             at android.app.ActivityThread.main(ActivityThread.java:7367)
                                                                             at java.lang.reflect.Method.invoke(Native Method)
                                                                             at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:469)
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963)

So i replaced this statement

final DfuServiceInitiator starter = new DfuServiceInitiator(mSelectedDevice.getAddress())
                .setDeviceName(mSelectedDevice.getName())
                .setKeepBond(keepBond);

with

        final DfuServiceInitiator starter = new DfuServiceInitiator(mSelectedDevice.getAddress())
                .setForeground(false)                // Foreground doesn't work correctly for android 8.1
                // See https://stackoverflow.com/questions/47531742/startforeground-fail-after-upgrade-to-android-8-1
                .setDeviceName(mSelectedDevice.getName())
                .setKeepBond(keepBond);

Instead I think that startForeground should be implemented according to this issue notified on stackoverflow: https://stackoverflow.com/questions/47531742/startforeground-fail-after-upgrade-to-android-8-1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
nijat2018commented, Nov 14, 2018

I have the same issue on my Android Things Board and solved by starter.setForeground(false); starter.setDisableNotification(true); Anyway I don’t need them.

0reactions
philips77commented, May 10, 2019

@1ALo

what is starter in your code ?

starter is the DfuServiceInitiator, I guess.

Read more comments on GitHub >

github_iconTop Results From Across the Web

startForeground fail after upgrade to Android 8.1
RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: ...
Read more >
Bad notification for startForeground crash on >= Android 8.1 ...
@philips77 I am experiencing the same issue, which crashes our app whenever we try to run a DFU. Here is the error: FATAL...
Read more >
【错误记录】前台进程报错( Bad notification for ... - CSDN博客
android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service ...
Read more >
DFU App Crash - Bad notification for startForeground
So I came across an issue while working on developing an app that can update firmware OTA. I was using Nordic Semi -...
Read more >
Bad notification for startForeground: java.lang ... - 51CTO博客
RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException,安卓开发8.1以上系统启动服务和通知报错 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