我们在办公室遇到了同样的问题,这就是我在这里看到你的帖子的原因。我测试了三个不同的Nexus 9设备(仅WiFi),每种情况下它们都成功注册推送......但从服务器发送的通知却从未收到过。
我进行的第一项测试使用了我们现有的Android应用程序和服务器。在此不成功后,我从Google Play商店下载了
Push Notification Test。这在其他设备上运行得非常好(Nexus 5等),但在Nexus 9上未能接收通知。
仅出于可能存在Play Store测试应用程序过时的问题,我创建了一个测试Android应用程序和服务器脚本,以查看是否可以进一步缩小问题范围。我遇到了相同的问题。除了Nexus 9之外,我测试的每个设备都注册并接收了推送通知。我尝试改变项目中Google Play服务库的版本(从最新版本到几个版本之前),但没有效果。
在我上述的最后一次尝试中,我使用了此处找到的GCM演示应用程序:GCM客户端,以及一个基于另一个用户代码修改的php脚本(显然已删除密钥和注册ID):
<?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;
更新:我们已经将办公室里的三个平板电脑升级到5.0.1 OTA,但是这些平板电脑仍然无法接收推送通知。谷歌方面也没有任何消息,但希望下一次OTA能够修复这个问题。
更新:在1月13日,我们注意到Nexus 9开始接收推送通知。显然谷歌已经解决了这个问题。圆满完成。