phonegap / phonegap-plugin-push

Register and receive push notifications
MIT License
1.94k stars 1.92k forks source link

Android 8 not playing sound / vibrations #2221

Open meisterm opened 6 years ago

meisterm commented 6 years ago

Expected Behaviour

App should play sound (Custom, Ringtone or default notification sound) and vibrate when notification received.

Actual Behaviour

Notification is shown but no vibration and no sound is played.

Reproduce Scenario (including but not limited to)

Setup a new Ionic Project with Plugin Push v2. Registration, Receiving of Push Message (showing up), Icon etc. is working. Only sound and vibration is missing. Additionally I use the cordova-background-geolocation-lt 2.10.1 "BackgroundGeolocation" Plugin in my app which uses the Google Services as well.

Steps to Reproduce

Nothing special. Install plugin, take my init Options and send the FCM Message.

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

Android 8.0 with OxygenOS 5.0.2

(Android) What device vendor (e.g. Samsung, HTC, Sony...)

One Plus 5

Cordova CLI version and cordova platform version

cordova --version                                    # 7.1.0
cordova platform version android                     # 6.3.0

Plugin version

cordova plugin version | grep phonegap-plugin-push   # 2.1.3

Google-API Version: 11.6.2

Sample Push Data Payload

{
    "registration_ids": ["xxx"],
    "data": {
        "title": "Testtitle",
        "message": "Testmessage"
    },
    "priority": "high"
}

Sample Code that illustrates the problem

Init Options for Push Plugin:

let actionEinsatz: CategoryAction = {
            yes: {
                callback: "accept",
                title: "Annehmen",
                foreground: true,
                destructive: false
            },
            no: {
                callback: "decline",
                title: "Ablehnen",
                foreground: true,
                destructive: false
            },
            maybe: {
                callback: "later",
                title: "Später",
                foreground: true,
                destructive: false
            }
        };
        const options: PushOptions = {
            android: {
                senderID: '313658594957',
                forceShow: true,
                sound: true,
                vibrate: true,
                clearBadge: true,
                iconColor: 'red',
                icon: 'ambulance'
            },
            ios: {
                alert: true,
                badge: true,
                sound: true,
                clearBadge: true,
                categories: { "einsatz": actionEinsatz }
            },
            windows: {}
        };

 const pushObject: PushObject = this.push.init(options);

Logs taken while reproducing problem

02-23 17:36:11.514 9927 10041 D Push_FCMService: onMessage - from: 313658594957 02-23 17:36:11.516 9927 10041 D Push_FCMService: normalize extras 02-23 17:36:11.516 9927 10041 D Push_FCMService: key = title 02-23 17:36:11.516 9927 10041 D Push_FCMService: replace key title with title 02-23 17:36:11.516 9927 10041 D Push_FCMService: no locale found for key = title, error Value Testtitle of type java.lang.String cannot be converted to JSONObject 02-23 17:36:11.517 9927 10041 D Push_FCMService: key = message 02-23 17:36:11.517 21010 21093 E ExecutionCriteria: Package unavailable for task: com.google.android.talk/com.google.android.apps.hangouts.concurrent.impl.GcmTriggeredNotifier{u=0 tag="network_connectivity_wakeup:persisted" trigger=window{start=265018s,end=265019s,earliest=-20467370s,latest=-20467369s} requirements=[NET_CONNECTED] attributes=[PERSISTED] scheduled=-20732388s last_run=N/A jid=N/A status=PENDING retries=0 client_lib=MANCHEGO_GCM-0} 02-23 17:36:11.517 9927 10041 D Push_FCMService: replace key message with message 02-23 17:36:11.517 9927 10041 D Push_FCMService: no locale found for key = message, error Value Testmessage of type java.lang.String cannot be converted to JSONObject 02-23 17:36:11.519 9927 10041 D Push_FCMService: background 02-23 17:36:11.519 9927 10041 D Push_FCMService: message =[Testmessage] 02-23 17:36:11.519 9927 10041 D Push_FCMService: title =[Testtitle] 02-23 17:36:11.519 9927 10041 D Push_FCMService: contentAvailable =[null] 02-23 17:36:11.519 9927 10041 D Push_FCMService: forceStart =[null] 02-23 17:36:11.519 9927 10041 D Push_FCMService: create notification 02-23 17:36:11.520 9927 10041 E Push_FCMService: Number format exception - Error parsing notId: s == null 02-23 17:36:11.524 9927 10041 D Push_FCMService: Using channel ID = de.xxx.yyyTSLocationManager 02-23 17:36:11.528 9927 10041 D Push_FCMService: stored icon=ambulance 02-23 17:36:11.528 9927 10041 D Push_FCMService: stored iconColor=red 02-23 17:36:11.528 9927 10041 D Push_FCMService: stored sound=true 02-23 17:36:11.528 9927 10041 D Push_FCMService: stored vibrate=true 02-23 17:36:11.528 9927 10041 D Push_FCMService: using icon from plugin options 02-23 17:36:11.532 9927 10041 D Push_FCMService: create actions: with in-line 02-23 17:36:11.533 9927 10041 W Notification: Use of stream types is deprecated for operations other than volume control 02-23 17:36:11.533 9927 10041 W Notification: See the documentation of setSound() for what to use instead with android.media.AudioAttributes to qualify your playback use case 02-23 17:36:11.541 20153 20153 D NotificationListener: onNotificationPosted# hash: 48799964 sbn: StatusBarNotification(pkg=de.xxx.yyy user=UserHandle{0} id=0 tag=YYY key=0|de.xxx.yyy|0|YYY|10225: Notification(channel=de.xxx.yyyTSLocationManager pri=0 contentView=null vibrate=default sound=content://settings/system/notification_sound tick defaults=0x2 flags=0x10 color=0xffff0000 vis=PRIVATE)) 02-23 17:36:11.584 2513 2513 D StatusBar: updateMediaMetaData: hasArtwork = true, 0, false, true, 8, false, false, false, 0, false

macdonst commented 6 years ago

@meisterm you didn't put the sound property into your payload in order to tell the plugin to play a sound. Please read: https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/PAYLOAD.md#sound

meisterm commented 6 years ago

Hi, sorry I tested all possible soundname constellations. The goal is to play a custom sound but after this didn't work I tested the other variants. So these are the logs with the payload for default sound:

{ "registration_ids": ["xxx"], "data": { "title": "Testtitle", "message": "Testmessage", "soundname": "default" }, "priority": "high" }

Log:

02-24 10:42:04.825 11676 16166 D Push_FCMService: onMessage - from: 313658594957 02-24 10:42:04.840 11676 16166 D Push_FCMService: normalize extras 02-24 10:42:04.840 11676 16166 D Push_FCMService: key = soundname 02-24 10:42:04.840 11676 16166 D Push_FCMService: replace key soundname with sound 02-24 10:42:04.840 11676 16166 D Push_FCMService: key = title 02-24 10:42:04.840 11676 16166 D Push_FCMService: replace key title with title 02-24 10:42:04.841 11676 16166 D Push_FCMService: no locale found for key = title, error Value Testtitle of type java.lang.String cannot be converted to JSONObject 02-24 10:42:04.841 11676 16166 D Push_FCMService: key = message 02-24 10:42:04.841 11676 16166 D Push_FCMService: replace key message with message 02-24 10:42:04.841 11676 16166 D Push_FCMService: no locale found for key = message, error Value Testmessage of type java.lang.String cannot be converted to JSONObject 02-24 10:42:04.851 21010 21093 E ExecutionCriteria: Package unavailable for task: com.google.android.talk/com.google.android.apps.hangouts.concurrent.impl.GcmTriggeredNotifier{u=0 tag="network_connectivity_wakeup:persisted" trigger=window{start=265018s,end=265019s,earliest=-20528923s,latest=-20528922s} requirements=[NET_CONNECTED] attributes=[PERSISTED] scheduled=-20793941s last_run=N/A jid=N/A status=PENDING retries=0 client_lib=MANCHEGO_GCM-0} 02-24 10:42:04.863 11676 16166 D Push_FCMService: background 02-24 10:42:04.864 11676 16166 D Push_FCMService: message =[Testmessage] 02-24 10:42:04.864 11676 16166 D Push_FCMService: title =[Testtitle] 02-24 10:42:04.864 11676 16166 D Push_FCMService: contentAvailable =[null] 02-24 10:42:04.864 11676 16166 D Push_FCMService: forceStart =[null] 02-24 10:42:04.864 11676 16166 D Push_FCMService: create notification 02-24 10:42:04.865 11676 16166 E Push_FCMService: Number format exception - Error parsing notId: s == null 02-24 10:42:04.874 11676 16166 D Push_FCMService: Using channel ID = de.xxx.yyyTSLocationManager 02-24 10:42:04.913 11676 11681 I zygote64: Method exceeds compiler instruction limit: 25337 in void org.ccil.cowan.tagsoup.HTMLSchema.() 02-24 10:42:04.925 11676 16166 D Push_FCMService: stored icon=ambulance 02-24 10:42:04.925 11676 16166 D Push_FCMService: stored iconColor=red 02-24 10:42:04.925 11676 16166 D Push_FCMService: stored sound=true 02-24 10:42:04.925 11676 16166 D Push_FCMService: stored vibrate=true 02-24 10:42:04.925 11676 16166 D Push_FCMService: using icon from plugin options 02-24 10:42:04.928 11676 16166 D Push_FCMService: create actions: with in-line 02-24 10:42:04.928 11676 16166 W Notification: Use of stream types is deprecated for operations other than volume control 02-24 10:42:04.928 11676 16166 W Notification: See the documentation of setSound() for what to use instead with android.media.AudioAttributes to qualify your playback use case 02-24 10:42:04.935 20153 20153 D NotificationListener: onNotificationPosted# hash: 48799964 sbn: StatusBarNotification(pkg=de.xxx.yyy user=UserHandle{0} id=0 tag=YYY key=0|de.xxx.yyy|0|YYY|10225: Notification(channel=de.xxx.yyyTSLocationManager pri=0 contentView=null vibrate=default sound=content://settings/system/notification_sound tick defaults=0x2 flags=0x10 color=0xffff0000 vis=PRIVATE)) 02-24 10:42:04.969 2513 2513 D StatusBar: updateMediaMetaData: hasArtwork = true, 1, true, true, 0, false, false, false, 0, false

Beacuse of the use of the background-geolocation plugin there is a permanent notification on the android screen. Is it possible that there are some influences between these both plugins? (I can read something about "TSLocationManager" in the Notification Channel)

meisterm commented 6 years ago

I did some further research regarding the geolocation-background-lt Plugin. I saw that there is a NotificationChannel created by this plugin called "de.xxx.yyyTSLocationManager". When I call listChannels from the push-plugin I get this one Channel back. When I try to create another channel with a custom ID it doesn't seem to work because when I call listChannels after that again the new Channel isn't listed. Also the FCM Notification will not be shown -> logcat tells me that there is no such channel.

Is it possible that sound and vibration is not working because of the missing Notification Channel? By default it looks like, that the "de.xxx.yyyTSLocationManager" NotificationChannel is also used by the push-plugin when showing the Notification.

meisterm commented 6 years ago

Now I have some more information:

After checking the NotificationChannel of the GeolocationBackground Plugin I could determine that the notification sound and vibration was turned off in settings. After turning on I became sound and vibration. But only the default one. Custom Sound and Vibration Pattern didn't work.

Than I removed the Geolocation completely from my app and remove and rebuild the app on the device. Now the default NotificationChannel channel=PushPluginChannel exists and is used when a Notification is displayed. But still custom sound and vibration doesn't work. Even creating and removing of custom NotificationChannels is not possible. Currently I'm testing Google-Api Version 11.8.0 even without success, too.

idekterev commented 6 years ago

I can also confirm the lack of custom sounds - Tested on Android 8.1.0. 'soundname' seems to not have any effect. Even the example using the value of "soundname": "ringtone" does not play the ringtone, just the default notification sound.

As an idea it would be great to configure the 'default' sound in the PushNotification.init block, just like we can set the default icon with: "android": { "icon": "custom_icon_name", }

JSON Payload: { "registration_ids": ["my device id"], "data": { "title": "Ringtone", "message": "Plays default ringtone sound", "soundname": "ringtone" } }

p.s. my Logcat showed the exact same entries that may be related:

W/Notification: Use of stream types is deprecated for operations other than volume control W/Notification: See the documentation of setSound() for what to use instead with android.media.AudioAttributes to qualify your playback use case

meisterm commented 6 years ago

Can you give us some feedback?

tominou commented 6 years ago

Same here, custom sound is not working on Android 8.1

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

warthog618 commented 5 years ago

I'm still seeing this problem with plugin v2.2.3 and soundname: "ringtone". Works for Android 7.1.2, but not for 8.1.

panchazo commented 5 years ago

Based on my experience the sound must be set in the javascript side when creating the channel for android 8+. Sending the sound in the payload will only work on Android 7 and lower.