我試圖接收推送通知消息併發送通知消息,但我得到的空值沒有收到任何消息。如何在android中獲取推送通知消息?
下面的代碼
@Override
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
Log.d("push","msg type: " + messageType);
if (!extras.isEmpty()) {
if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR
.equals(messageType)) {
} else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED
.equals(messageType)) {
} else if (!extras.isEmpty() && GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE
.equals(messageType)) {
Log.d("push notify msg: ", extras.toString());
sendNotification(extras.toString());
}
}
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
參考此鏈接可能會幫助您:http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and- mysql/ –