question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot mute sound or vibration on Android 8.x

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:32

github_iconTop GitHub Comments

2reactions
klochko7commented, Dec 11, 2018

I am using Android 8 and vibration is present too !

2reactions
Steffaancommented, Sep 14, 2018

@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.

channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, IMPORTANCE_HIGH);
  if(!options.isSilent()) channel.setBypassDnd(true);
  if(!options.isWithoutLights()) channel.enableLights(true);
  channel.enableVibration(options.isWithVibration());
  channel.setLightColor(options.getLedColor());
  if(options.isWithoutSound()) {
      channel.setSound(null, null);
  } else {
      channel.setSound(options.getSound(), null);
  }

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

cordova.plugins.notification.local.schedule({
      id: 1,
      title: 'Title of your notification',
      text: 'Text of your notification',
      sticky: true, // Only use this is you want your notification to be sticky / ongoing!
      lockscreen: true, // Only use this if you want the notification to be shown in lockscreen!
      foreground: true, // Only use this if you want to show the notification when app is in foreground
      priority: 2, // High priority
      actions: [
            { id: 'acceptPush', title: 'Accept' }, // Example for an action button
            { id: 'denyPush', title: 'Deny' } // Example for an action button
      ]
});

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 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Notifications: turn off sounds & vibrations - Google Support
Notifications: turn off sounds & vibrations · Tap your profile picture . · Tap Settings "" . · Tap Notifications. · Turn Disable...
Read more >
Developers - Cannot mute sound or vibration on Android 8.x -
Cannot mute sound or vibration on Android 8.x.
Read more >
How to Turn Off Vibration on Android Devices - Lifewire
Go to Settings > Sound & Vibration and toggle the settings to switch vibration off. · You can also go to Settings >...
Read more >
Cannot disable notification vibration in Android 8
It is still vibrating. · simply remove vibrate permission from manifest and try once. – Akshay Katariya · @AkshayKatariya Doesn't work · Remember ......
Read more >
How to Turn Off Vibration on Android - YouTube
In this video I'll show you how to turn off vibrations on Android.See more videos by Max here: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found