Bad notification for startForeground
See original GitHub issueOn 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:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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.@1ALo
starter is the DfuServiceInitiator, I guess.