Google GCM - Not receiving push notifications in a

2019-02-07 01:26发布

问题:

In my android application I use GCM to receive message from my company server.

I wrote the code for c2dm and I followed the instructions for migrating the code to GCM. (http://developer.android.com/google/gcm/c2dm.html)

In android Lollipop (Nexus 9 wifi), the device registers for push notifications and receives the push registration id, but when I send a message from my server, in the device I don't receive any message.

In previous android versions (from 4.0 to 4.4) I haven't any problems.

Do you know of any problems in push notifications of Lollipop?

Thanks

回答1:

We encountered the same problem in our office, which is why I stumbled upon your post here. I've tested three separate Nexus 9 devices (WiFi Only), and in each case all of them successfully registered for push...but never receive any notifications that are sent from the server.

The first test I did used our existing android application and server. After this was unsuccessful I downloaded Push Notification Test from the Google Play Store . This worked flawlessly on other devices (Nexus 5...etc), but failed to receive notifications on the Nexus 9.

Just for the sake of a possible issue with the Play Store Test application being out of date, I created a test Android application and server script to see if I could narrow the problem down further. I encountered the same issue. Every device I tested with the exception of the Nexus 9 registered and received push notifications. I tried varying the version of the Google Play Services library in the project (from newest to a few versions back), but that had no effect.

For my last attempt mentioned above I used the GCM demo application found here: GCM Client along with a php script I modified based on another user's code (with keys and reg id's removed obviously):

<?php

$nexus5 = '';
$nexus9 = '';
$nexus9Alt = '';
$registrationIds = array($nexus5,$nexus9,$nexus9Alt);

$apiKey = '';

$msg = array
(
    'message'       => 'Do you know smell what the rock is cooking?',
    'title'         => 'Push Test',
    'subtitle'      => 'This is a subtitle',
    'tickerText'    => 'This is the ticker',
    'vibrate'       => 1,
    'sound'         => 1
);

$fields = array
(
    'registration_ids'  => $registrationIds,
    'data'              => $msg
);

$headers = array
(
    'Authorization: key=' . $apiKey,
    'Content-Type: application/json'
);

$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );

echo $result;

Update: We updated the three tablets in office to the 5.0.1 OTA, and the tablets still will not receive push notifications. No news from google on these either, but hopefully it will be fixed in the next OTA.

Update: On January 13th we noticed that the Nexus 9's started receiving push notifications. Apparently Google fixed it. The circle is complete.



回答2:

I have a fairly simple GCM app for Android that works fine on Kitkat. After the lollypop upgrade, the 'Explicit Intent' error occurs (Android 5.0 (L) Service Intent must be explicit in Google analytics). I fixed that and there are no error but also no device registration!



回答3:

I got solution of this problem by testing of GCM pull notification on mobile network instead of office WIFI.