Steffaan / cordova-plugin-local-notifications

Cordova Local Notifications Plugin
Apache License 2.0
31 stars 38 forks source link

Unable to change vibration and sound settings once configured #1

Closed hordesalik closed 5 years ago

hordesalik commented 5 years ago

Android 8.1 Cordova 8.0.0

Installed platforms: android 7.1.0

Plugins: cordova-plugin-badge 0.8.8 "Badge" cordova-plugin-device 2.0.2 "Device" cordova-plugin-local-notification 0.9.0-beta.3 "LocalNotification" cordova-plugin-whitelist 1.3.3 "Whitelist"

local notifications plugin config:

Hi @Steffaan , I need to get this code work:

cordova.plugins.notification.local.schedule({
            id: 1,
            title: 'Downloading...',
            text: 'File name',
            sound: false,
            vibrate: false,
            progressBar: {value: 0},
        });

        for (var i = 1; i <= 5; i++) {
            (function (i) {
                setTimeout(function () {
                    cordova.plugins.notification.local.update({
                        id: 1,
                        progressBar: {value: i * 20},
                    })
                }, i * 1000);
            })(i);
        }

        setTimeout(function () {
            cordova.plugins.notification.local.clearAll([1]);
            cordova.plugins.notification.local.schedule({
                id: 2,
                title: 'Download completed',
                text: 'File name',
                sound: true,
                vibrate: true,
            })
        }, 6000);

As you can see, I'm trying to emulate file downloading. Progress notifications shouldn't vibrate or play sound, but once file is downloaded, final notification sould vibrate and make sound. This doesn't work. `. So there are 2 problems:

  1. Once I set sound: false, vibrate: false in first notification, I can't change them in the second one.
  2. I need to remove and install application to change anything in sound and vibrate settings.
Steffaan commented 5 years ago

Because the plugin creates a channel based on the first notification, every notification in your app uses the settings from that single channel. Thats why the second notification won't trigger any sound or vibration.

I need to change the whole method so you can create multiple channels to use different settings, not sure if I have the time to fix it any time soon. Perhaps in the weekend.

Same thing goes for your second issue, that's the way Android works.

After you create a notification channel, you cannot change the notification behaviors—the user has complete control at that point. Though you can still change a channel's name and description.

You should create a channel for each distinct type of notification you need to send. You can also create notification channels to reflect choices made by users of your app. For example, you can set up separate notification channels for each conversation group created by a user in a messaging app.

Source: https://developer.android.com/training/notify-user/channels

So that's basically fixed too if I change the plugin to support multiple channels.

I'll keep you updated if i'm done with these changes.

hordesalik commented 5 years ago

Okay, undestood. Maybe we can just use "channel" settings to manually manage channels. So original code wouldn't changed, but if channel is specified, messages will go directly in this channel.

Steffaan commented 5 years ago

Fixed and commited. Plugin now supports multiple channels.

By defining the property channel inside your notification, that specific channel will be created. There is a new property called channelDescription which will declare the description for the created channel.

Both of your issues should be fixed with this update. I also fixed the priorities, they get attached to the channel too now. When a channel is given a priority higher then PRIORITY_DEFAULT it will bypass DND in android (Do not disturb mode).

hordesalik commented 5 years ago

Yeah, that's cool, it works. Thank you VERY VERY MUCH. But... another issue produced #2

stsier commented 5 years ago

same problem using 0.9.0-beta.2 samsung 9 android 8.1

setting sound: false, vibrate: false still makes sound or vibrates also can't remove badge and another off topic: why only three actions? I need five for instance

Steffaan commented 5 years ago

same problem using 0.9.0-beta.2 samsung 9 android 8.1

setting sound: false, vibrate: false still makes sound or vibrates also can't remove badge and another off topic: why only three actions? I need five for instance

I'd appreciate if you actually read the entire issue and the fact that it's solved. You mention that your using 0.9.0 beta, but that's not the version used in this repo. Perhaps you should try to download the version in this repo and try again.

To answer your question about the maximum of three actions, that's how it works in Android.

A notification in its expanded form can display up to 3 actions, from left to right in the order they were added.

Source: https://developer.android.com/reference/android/app/Notification.Builder#addAction(android.app.Notification.Action)