pmwisdom/cordova-background-geolocation-services

android@8.1 getting crashed while start the service

Opened this issue · 1 comments

android@8.1 getting crashed while start the service

Hey @dassram17,

I had the same problem at Android 8 (API26+). I upgraded my working App from TargetApi 26 to TargetApi 28 (Android 8) and this Plugin didn't work anymore. It always caused a crash as the app started going into Background-Mode.

The Logs showed this error:

--------- beginning of crash 2020-03-28 11:55:12.456 /? E/AndroidRuntime: FATAL EXCEPTION: main Process: android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=null pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x62 color=0x00000000 vis=PRIVATE) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1945) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

As it says in the new documentation from Android 8:

Before you can deliver the notification on Android 8.0 and higher, you must register your app's notification channel with the system by passing an instance of NotificationChannel to createNotificationChannel(). So the following code is blocked by a condition on the SDK_INT version

https://developer.android.com/training/notify-user/build-notification

It works now with my adjustments

So the crash is caused, because the notification of this plugin has no channel defined. After I found out about this problem, I created a copy of this plugin. I created a Notification Channel and added it to the notification of this plugin. Now it works find, without crashes!

https://github.com/MaxKicw/background-activity-plugin

Hope it helps!

Not sure how we can merge my fix with this branch. Mabye need some help, If this ist possible :) @pmwisdom

Cheers,
Max