havesource / cordova-plugin-push

Register and receive push notifications
MIT License
149 stars 284 forks source link

Android volume controlled by “Ringtone” settings #40

Open EtienneLem opened 4 years ago

EtienneLem commented 4 years ago

Bug Report

Notifications sound volume seems to be unexpectedly controlled by the “Ringtone” settings:

Screen Shot 2020-09-30 at 8 27 18 AM

The sound played is the system’s notification sound, not the ringtone one. We’re receiving reports of users being woken up in the middle of the night because of our notifications. That might be an issue on Samsung devices only. On a Pixel device the notification volume seems to be controlled by “Ring” volume:

Screen Shot 2020-09-30 at 8 56 42 AM

This (https://github.com/missive/cordova-plugin-push/commit/5b80995a9d83b22ad461d59ba7a1ff24f729b68b) was our naive attempt at fixing this based on this documentation (https://developer.android.com/reference/android/media/AudioAttributes), but it did not have any effect.

Reproduce Scenario (including but not limited to)

Platform and Version (eg. Android 5.0 or iOS 9.2.1)

• Android 9 • Android 10

(Android) Device Vendor (e.g. Samsung, HTC, Sony...)

Samsung devices only as far as we can tell • Galaxy S9+ • Galaxy S8+ • Note 9

Sample Push Data Payload

{
  "sound": "default",
  "title": "Title",
  "body": "Body",
  "notId": "[INCREMENTAL_NUMBER]",
}

Sample Code that illustrates the problem

Our plugin init looks like this:

PushNotification.init({
  ios: {
    alert: true,
    badge: true,
    sound: true,
  },
  android: {
    senderID: SENDER_ID,
    sound: true,
    vibrate: true,
    icon: 'notification',
    iconColor: '#2266ED',
  },
})
CryptoTradee commented 4 years ago

Strange, I was just about to raise an issue that I don't get any notification sound if I don't use the notification node? That was on my Oppo Reno Z but think it happened on a Samsung too

JoshBoehm commented 3 years ago

I can confirm the same behavior on a Samsung Galaxy S10+ as well.

Notification sounds are being treated as a "Ringtone".

Other really annoying side effects from this are that the notification audio plays through speaker, even if headphones are in, and it plays over other playing media without pausing it.

nelsonbarrac commented 1 year ago

The issue still remains unsolved. I tested it on a galaxy a54.

davidhu3141 commented 10 months ago

What I do to workaround is to search for USAGE_NOTIFICATION_RINGTONE in plugin's android native code, and then replace it with USAGE_NOTIFICATION. It works in plugin v2.0.0 (java) but I think in v4.0.0 (kotlin) the workaround is similar.

Specifically, in v2.0.0 PushPlugin.java:

       AudioAttributes audioAttributes = new AudioAttributes.Builder()
         .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
-        .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE).build();
+        .setUsage(AudioAttributes.USAGE_NOTIFICATION).build();