distriqt / airnativeextensions

DEPRECATED: Original repository of the distriqt native extensions and is no longer maintained. Please see our site for the latest ANEs
https://airnativeextensions.com
2 stars 0 forks source link

PushNotifications trying to send notification and not show the actual notification. #288

Closed philvessey closed 9 years ago

philvessey commented 9 years ago

Hi

Using the code below.

            $headers = array("Content-Type:" . "application/json", "Authorization:" . "key=" . GCM_KEY);
            $messageData = array('message' => 'sync');
            $data = array('data' => $messageData, 'registration_ids' => $notificationRegistrationIds);

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
            curl_setopt($ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send");
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

            $response = curl_exec($ch);
            $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            curl_close($ch);

What I want to achieve is for the device to receive the notification but not show anything in the notification bar. A silent notification if you will that can trigger the device to sync when its running and do nothing when its not.

The notification works fine when including $tickerText, $contentTitle and $contentText etc

philvessey commented 9 years ago

While im at it is there anyway to make the notification text multiLine also? This would be the information in $contentText?

marchbold commented 9 years ago

Hi Phil,

What version of the extension are you using?

PushNotifications.service.version

I've confirmed the latest version from github (2.6.Android.2.2) doesn't show a notification with just 'message' in the data.

philvessey commented 9 years ago

Thats correct but when the application is already running and im listening for the notification with PushNotificationEvent.FOREGROUND_NOTIFICATION with just the message in the data the app doesnt seem to process the notification arriving.

Its as if removing those fields completely disables the notification. This is with 2.6.Android.2.2 on Android 5.0

philvessey commented 9 years ago

If its not something thats technically possible im quite happy still showing the actual notification (which is what im doing now) just wondered if there were other options.

marchbold commented 9 years ago

Ah, yes the foreground notification is only fired when the notification is displayed. Listen for this event instead:

PushNotificationEvent.NOTIFICATION
philvessey commented 9 years ago

Thanks Michael - changing the type of the event has sorted the issue. Its now running as I want it too.

marchbold commented 9 years ago

Sorry about that, I should have suggested that on Twitter.