cordova-plugin-background-mode: App crashes on android 9.0
Issue description
My app crashes on android 9.0(My phone is Xiaomi 8), it works well on earlier platform(Android 6.0, 7.0, 8.0).
It crashes when the screen turns off or I switch to another app.
Error log from Android Studio
Similar to https://github.com/katzer/cordova-plugin-background-mode/issues/393#issue-346518462
2019-02-21 21:08:28.938 6320-6320/cc.cs_tao.whu_library_seat_mobile E/AndroidRuntime: FATAL EXCEPTION: main
Process: cc.cs_tao.whu_library_seat_mobile, PID: 6320
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:1760)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6806)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
My project info
-
Repo whu-library-seat-mobile#83daf8357ffce4bbda762a04bc9e7005ee43784d
-
Node and Cordova version
- node v8.15.0
- cordova 8.1.2 (cordova-lib@8.1.1)
-
Build environment in travis-ci
android: components: - tools - build-tools-28.0.3 - android-27 - extra-android-m2repository - extra-android-support - extra-google-m2repository licenses: - 'android-sdk-license.*' -
cordova-plugin-background-modeversions I have tried -
Other cordova plugins in my project
{ "cordova-android": "~7.1.1", "cordova-plugin-advanced-http": "^2.0.1", "cordova-plugin-badge": "^0.8.7", "cordova-plugin-device": "^2.0.2", "cordova-plugin-file": "^6.0.1", "cordova-plugin-local-notification": "^0.9.0-beta.2" }
Can anyone help me? Many thanks.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 5
- Comments: 22
Commits related to this issue
- 不显示后台运行的通知 https://github.com/katzer/cordova-plugin-background-mode/issues/428 — committed to CS-Tao/whu-library-seat-mobile by CS-Tao 5 years ago
@markarupert
From the app plugin:
I was looking for another solution and found that:
It fixed my crash issue. Now just need to test if android 9 leaves the app running in the background or it kills it after 5 minutes.
So I just found out that when the
targetSdkVersionis set to27, the plugin works perfectly well but when changing it to28the issue is back, and can only be solved by actively adding theFOREGROUND_SERVICEpermission.I think this issue should be reopened and the permission should be included in the plugin itself.
It will not crash if I do not show the notification from this plugin.
Note: Notifications from
cordova-plugin-local-notificationstill work well in my app.@CS-Tao @KinG-InFeT for me this solution it’s working:
because the external package contains these changes https://github.com/katzer/cordova-plugin-background-mode/pull/389
@Genarito : ok sir I will try another solutiona and let u know it’s working or not.
@weglov Thank you, It works!
And @Genarito ‘s solutions can solve this problem, too. I’m sorry that I did not delete the caches in Travis-ci before, so Travis always releases the apk with the old plugin.
Try this:
That fixed the problem for me. And It fixed an iOS bug too where app didn’t start even.
Hope It helps