我正在关注http://javapapers.com/android/google-cloud-messaging-gcm-for-android-and-push-notifications/?通过GCM发送推送通知.一切正常,但我能够将推送通知发送到一个设备.注册其他设备会替换先前设备的注册ID.我试过Shardool在http://javapapers.com/android/android-multicast-notification-using-google-cloud-messaging-gcm/中提供的解决方案?但它不起作用.
任何建议都会有很大帮助.
以下是我的gcm.php代码,用于注册设备并发送推送通知,但仅限于最近注册的单个设备.
gcm.php
<?php
//generic php function to send GCM push notification
function sendPushNotificationToGCM($registatoin_ids, $message) {
//Google cloud messaging GCM-API url
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registatoin_ids,
'data' => $message,
);
// Google Cloud Messaging GCM API Key
define("GOOGLE_API_KEY", "MY_KEY");
$headers = array(
'Authorization: key=' . GOOGLE_API_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = …Run Code Online (Sandbox Code Playgroud)