cordova-plugin-local-notifications: Cannot mute sound or vibration on Android 8.x
WARNING: IF YOU IGNORE THIS TEMPLATE, WE’LL IGNORE YOUR ISSUE. YOU MUST FILL THIS IN!
Provide a general summary of the issue.
Your Environment
- Plugin version: 0.9.0-beta.2 and HEAD
- Platform: Android
- OS version: 8.0.0
- Device manufacturer / model: Samsung Galaxy S7
- Cordova version (
cordova -v): 8.0.0 - Cordova platform version (
cordova platform ls): android 7.0.0 - Plugin config
- Ionic Version (if using Ionic)
Expected Behavior
Tell us what should happen
A notification like this is scheduled:
cordova.plugins.notification.local.schedule({
id:
title: 'Testing
text: 'Vibrate set to false, sound set to false, priority set to
vibrate: false,
sound: false,
priority: -2 // NotificationCompat.PRIORITY_MIN
});
When fired, this notification should show up in the tray, but no sound or vibration is played.
Actual Behavior
Tell us what happens instead If the system notification sound level is not mute/vibrate, the phone plays the default notification sound when the notification appears.
If the system notification sound level is vibrate, the phone vibrates when the notification appears.
Steps to Reproduce
Reproduce this issue; include code to reproduce, if relevant
Schedule a notification with vibrate=false, sound=false, priority=-2
cordova.plugins.notification.local.schedule({
id: 0,
title: 'Testing notification',
text: 'Vibrate set to false, sound set to false, priority set to min',
vibrate: false,
sound: false,
priority: -2
});
I have a minimal example in this repository, it’s just the hello world app that fires on deviceready: https://github.com/eric-zeng/no-vibrate
Context
What were you trying to do?
I’m trying to show notifications that show up silently without disturbing the user. It should make no sound or vibration.
Debug logs
Include iOS / Android logs
- ios XCode logs
- Android: $ adb logcat
08-14 15:12:24.629 1403 1403 I CordovaActivity: Apache Cordova native platform version 7.0.0 is starting
08-14 15:12:24.629 1403 1403 D CordovaActivity: CordovaActivity.onCreate()
08-14 15:12:25.368 1403 1403 D CordovaWebViewImpl: >>> loadUrl(file:///android_asset/www/index.html)
08-14 15:12:25.423 1403 1403 D CordovaActivity: Started the activity.
08-14 15:12:25.437 1403 1403 D CordovaActivity: Resumed the activity.
08-14 15:12:25.516 1403 1403 D CordovaWebViewImpl: onPageDidNavigate(file:///android_asset/www/index.html)
08-14 15:12:26.365 1403 1403 D CordovaWebViewImpl: onPageFinished(file:///android_asset/www/index.html)
08-14 15:12:26.655 1403 1530 D local-notification: Next trigger at: Tue Aug 14 15:12:26 PDT 2018
08-14 15:12:26.695 1403 1530 W Notification: Use of stream types is deprecated for operations other than volume control
08-14 15:12:26.695 1403 1530 W Notification: See the documentation of setSound() for what to use instead with android.media.AudioAttributes to qualify your playback use case
08-14 15:12:26.701 1403 1530 D Notification: allPendingIntents
08-14 15:12:26.746 3986 5457 D Notification: allPendingIntents
08-14 15:12:26.747 3986 5371 D Notification: allPendingIntents
08-14 15:12:26.748 3986 5371 D Notification: allPendingIntents
08-14 15:12:26.750 3986 5457 D Notification: allPendingIntents
08-14 15:12:26.754 3986 5457 D Notification: allPendingIntents
08-14 15:12:26.757 3986 5371 D Notification: allPendingIntents
08-14 15:12:26.761 1403 1403 D CordovaWebViewImpl: >>> loadUrl(javascript:cordova.plugins.notification.local.fireEvent("trigger",{"id":0,"title":"Testing notification","text":"Vibrate set to false, sound set to false, priority set to min","vibrate":false,"sound":false,"priority":-2,"actions":[],"attachments":[],"autoClear":true,"clock":true,"defaults":0,"groupSummary":false,"launch":true,"led":true,"lockscreen":true,"number":0,"progressBar":{"enabled":false,"value":0,"maxValue":100,"indeterminate":false},"silent":false,"smallIcon":"res:\/\/icon","timeoutAfter":false,"trigger":{"type":"calendar"},"wakeup":true,"meta":{"plugin":"cordova-plugin-local-notification","version":"0.9-beta.3"}},{"event":"trigger","foreground":true,"queued":false,"notification":0}))
08-14 15:12:26.766 3986 5457 D Notification: allPendingIntents
08-14 15:12:26.775 1403 1403 D CordovaWebViewImpl: >>> loadUrl(javascript:cordova.plugins.notification.local.fireEvent("add",{"id":0,"title":"Testing notification","text":"Vibrate set to false, sound set to false, priority set to min","vibrate":false,"sound":false,"priority":-2,"actions":[],"attachments":[],"autoClear":true,"clock":true,"defaults":0,"groupSummary":false,"launch":true,"led":true,"lockscreen":true,"number":0,"progressBar":{"enabled":false,"value":0,"maxValue":100,"indeterminate":false},"silent":false,"smallIcon":"res:\/\/icon","timeoutAfter":false,"trigger":{"type":"calendar"},"wakeup":true,"meta":{"plugin":"cordova-plugin-local-notification","version":"0.9-beta.3"}},{"event":"add","foreground":true,"queued":false,"notification":0}))
08-14 15:12:35.703 5346 5346 D Notification: allPendingIntents
08-14 15:12:35.723 3986 5371 D Notification: allPendingIntents
08-14 15:12:35.724 3986 5371 D Notification: allPendingIntents
08-14 15:12:35.724 3986 5457 D Notification: allPendingIntents
08-14 15:12:35.725 3986 7209 D Notification: allPendingIntents
08-14 15:12:35.726 3986 5457 D Notification: allPendingIntents
08-14 15:12:35.726 3986 5371 D Notification: allPendingIntents
08-14 15:12:35.727 3986 6719 D Notification: allPendingIntents
About this issue
- Original URL
- State: open
- Created 6 years ago
- Comments: 32
I am using Android 8 and vibration is present too !
@angel1st You would be better of by using the fork I made, I will update and maintain it since we use the plugin for our own apps too.
But the problem with the katzer version is that Android 8 uses notification channels, where all functions need to be enabled before you can use them. That’s why your properties are not even used, even when you declare them.
What I did in the fork is setting the channel to HIGH_PRIORITY, this method prevents the app from ignoring the notifications when in Doze mode.
The changes needed to make the vibration and sound work again, is to pass the paramters to the channel before sending out notifications.
With the changes shown in the code above, you’ll be able to make the notification silent, enable / disable vibration, enable / disable LED, all of those options which stopped working with Android 8.
To use the changes I recommend you to trigger notifications with all properties included. This is an example of our integration (I put some comments in the code for you):
I also fixed /added the issue https://github.com/katzer/cordova-plugin-local-notifications/issues/1671 in my fork.
If you have any questions about the properties just let me know and I can explain them.
Good luck and I hope this helps you out 😃
@angel1st
Hello, your first issue is not a problem within the fork, same thing happens in the master version of katzer. The xml file is not deleted after removing the plugin.
I don’t have the issue fetching the plugin, are you sure everything is setup correctly on your environment?
Try
cordova plugin add https://github.com/Steffaan/cordova-plugin-local-notificationsI have the same issue ! I am using Samsung Galaxy android 8 and cannot mute sound or vibration.
Guys, I have one other case re local notification. Here is the scenario - While app is running, I am receiving local notification and it stays on the notification area. Now, if I click on the notification, while the app is running (either in front or background mode), it will trigger
clickevent, so I can handle this notification according to app logic. Then, I close the app. The notification is still on the notification area. So far so good. Now, if I open notification drawer and click on the notification, it will load the app, however, I don’t see anylocal-notificationevent being fired, hence I am not able to handle a specific notification type according to app logic. Any thoughts how this might be done?