且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Google GCM - 未在android棒棒糖中接收推送通知

更新时间:2022-12-19 14:07:39

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.