cordova-plugin-background-mode: Android 8.1 - invalid channel for service notification
i’m develope ionic app and there i’m used this plugin.
after opening my app and the app is loaded, i called the function “backgroundmode.enable()”. after a short timespan app stopped with the issue:
invalid channel for service notification
after removing the usage of this plugin the app isn’t stopped and runs all the time. all fine.
so, i checked this. i have added the plugin usage again and the exception came back. i removed it again, exception is gone
this is the full stacktrace, which is shown in Logcat (Android Studio):
android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=null pri=-2 contentView=null vibrate=null sound=null defaults=0x0 flags=0x42 color=0x00000000 vis=PRIVATE)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2105)
at android.os.Handler.dispatchMessage(Handler.java:109)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7377)
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)
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 9
- Comments: 20
@Gurjit-ONEBCG
Below changes in the cordova-plugin-background-mode worked for me. Crash issue is resolved as well as background plugin is working fine.
import android.app.NotificationChannel;b) Add below global variables:c) Replace keepAwake() method with below code:
Add below in AndroidManifest.xml file:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />In code where I invoked background mode plugin, used disableWebViewOptimizations option on activate:
Alternately, you can try https://github.com/katzer/cordova-plugin-background-mode/pull/416 but do remember to add FOREGROUND_SERVICE permission in AndroidManifest
@maerlynflagg I also spent long time to solve this problem. I solved this problem with below github (fork version).
try below command.
@katzer any chance?
Have similar issues with Android 8.1 however re-adding the platform didn’t resolve it. On Android P (Pixel 2) I receive the following error:
Issue: java.lang.RuntimeException: Unable to create service de.appplant.cordova.plugin.background.ForegroundService: java.lang.SecurityException: Permission Denial: startForeground from pid=17789, uid=10151 requires android.permission.FOREGROUND_SERVICESo if I add the permission android.permission.FOREGROUND_SERVICE I get the fatal exception:android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notificationLooks like an update might be needed - maybe something like this? ([https://stackoverflow.com/questions/47531742/startforeground-fail-after-upgrade-to-android-8-1])
EDIT: thanks @writer0713 that version has the fixes, updating ForegroundService.java with the updates from that git fixed the issue!
Hi,
You could add FOREGROUND_SERVICE permission in your app once without updating AndroidManifest everytime you build the app.
Add those lines to your config.xml to grant the missing permission:
<config-file parent="./" target="app/src/main/AndroidManifest.xml" xmlns:android="http://schemas.android.com/apk/res/android"> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> </config-file>Any chance on this solution be added to the main repo code?
yes! I made tests in android 8.1 and it is working fine!!
@writer0713 This fixed the crash issue, but background plugin stopped working 😦