Java GCM推送通知
我能够成功地从GCM发送推送通知,但无法捕获来自意图数据的消息。 消息变量未获取任何数据 我的GCMinentService课程Java GCM推送通知,java,android,push-notification,google-cloud-messaging,Java,Android,Push Notification,Google Cloud Messaging,我能够成功地从GCM发送推送通知,但无法捕获来自意图数据的消息。 消息变量未获取任何数据 我的GCMinentService课程 protected void onMessage(Context context, Intent data) { String message; message = data.getExtras().getString("message"); Log.i("message",data.toString()); Intent intent
protected void onMessage(Context context, Intent data) {
String message;
message = data.getExtras().getString("message");
Log.i("message",data.toString());
Intent intent = new Intent(this, GCMMessageView.class);
intent.putExtra("message", message);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setWhen(System.currentTimeMillis())
.setContentTitle("Android GCM Tutorial")
.setContentText(message).setContentIntent(pIntent)
.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(R.string.app_name, notification);
}
我的有效载荷
{
"message": "Hi I am nutritown",
"registration_ids":["registrationId"]
}
GCM的回应
{“多播_-id”:8633384191969300942,“成功”:1,“失败”:0,“规范_-id”:0,“结果”:[{“消息_-id”:“0:1420884152153321%b49c80e8f9fd7ecd”}]}
我的android清单文件
<permission android:name="com.androidbegin.gcmtutorial.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.androidbegin.gcmtutorial.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".GCMMainActivity"
android:launchMode="singleTask" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".GCMMessageView" >
</activity>
<service android:name=".GCMIntentService" />
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.androidbegin.gcmtutorial" />
</intent-filter>
</receiver>
</application>
问题已经解决,我的请求有误 对GCM服务器的正确请求应为
{
"data": {
"message": "Hi I am message",
"key2": "value2"
},
"registration_ids":["registrationid"]
}