cordova-plugin-local-notifications icon indicating copy to clipboard operation
cordova-plugin-local-notifications copied to clipboard

Channel works OK on Android 8 but not 9

Open andersborgabiro opened this issue 6 years ago • 6 comments

When submitting an app to Google Play I get a complaint about invalid channel for Android 9, but not for 8.

Your Environment

  • Plugin version: 979c65e
  • Platform: Android
  • OS version: 9
  • Device manufacturer / model: Google Pixel 2
  • Cordova version (cordova -v): cli-8.0.0
  • Cordova platform version (cordova platform ls): 7.0.0
  • Plugin config: See below
  • Ionic Version (if using Ionic): n/a

Expected Behavior

It should work also for Android 9, but...

Actual Behavior

I get this exception by Play's platform verification:

Exception 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)

Steps to Reproduce

config.xml:

    <plugin name="cordova-plugin-local-notifications" spec="https://github.com/Steffaan/cordova-plugin-local-notifications"/>

Use:

function notificationPermission() {
    if (typeof cordova.plugins.notification.local !== "undefined") {
        cordova.plugins.notification.local.requestPermission();
    }
}

function notificationAdd(message, badge) {
    if (typeof cordova.plugins.notification.local !== "undefined") {
        console.log("notificationAdd");

        if (message.length > MESSAGELENGTH) {
            message = message.substr(0, MESSAGELENGTH) + "…";
        }

        cordova.plugins.notification.local.schedule(
                {
                    channel: "Primary",
                    id: NOTIFICATIONID,
                    text: message,
                    badge: badge || 0,
                    autoClear: true,
                    sticky: false
                }
        );
    }
}

Debug logs

No access to that (as far as I know) as the verification was done at Google Play.

andersborgabiro avatar Jan 16 '19 16:01 andersborgabiro

@andersborgabiro

Looks like you didn't install this fork correctly. Are you sure that your app uses my version in the release which produces this error?

The error given is because there is no channel created for the notification.

Uninstall the app from your phone, create a new release and install your app again.

Let me know if this fixes your issue.

Steffaan avatar Jan 30 '19 13:01 Steffaan

I'll try again later today.

I currently don't have a phone with Android 9, so I have to rely on the verification done by Google Play.

andersborgabiro avatar Jan 30 '19 13:01 andersborgabiro

I just saw that the config.xml info didn't show. Added to the initial report.

andersborgabiro avatar Jan 30 '19 16:01 andersborgabiro

Long after publishing I got a prelaunch report (I guess that's how Google Play works) and it still complains about Android 9, which might be because I use SDK for 27 or something else unrelated. Anyway, this is what I get again (I do set the channel):

Google Pixel 2 (walleye) - Android 9

Exception 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)

andersborgabiro avatar Jan 31 '19 15:01 andersborgabiro

@Steffaan Anything new regarding this? I'm also getting the RemoveServiceException errors in the Play Console Android Vitals section and it is related to the local notification plugin. It happens both in the Katzer's and Steffaan's versions (both the latest) and it is not reported in an app with no the local notification plugins. The report in Android Vitals is generated for Android 7.x and 8.x but not for older and newever versions. I've tried the SDK 28 and 29 and I'm on the newest cordova Android platform 8.1.0. An example Google Play report looks like this:

android.app.RemoteServiceException: 
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1701)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:154)
  at android.app.ActivityThread.main (ActivityThread.java:6242)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:889)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:779)

There's nothing more in the report but I'm pretty sure the error is related to the notification plugin. I've got a proper smallicon (some suggested the reason is lacking a correct notification icon in the resources). I suppose it is related to this issue so maybe you hacve some ideas you can shared to get rid because after updating my app my crashing stats increased 1000% in the play console and the quality factor is one of the factors used by google when position apps in the listings.

rafaellop avatar Nov 28 '19 10:11 rafaellop

@Steffaan I've downgraded to the version 0.9.0-beta.3 from Katzer and the exception is no longer reported in the Google Play for any Android version. I'm pretty sure it has something to do with the channel code added in the following versions.

rafaellop avatar Dec 13 '19 08:12 rafaellop