問題是我的GCM消息到達我的應用程序,但沒有(自動)顯示在屏幕上。應該通過Android顯示到達的GCM消息嗎?
07-06 21:33:11.525 11269-11269/com.example.myapp D/ActivityThread: BDC-Calling onReceive: intent=Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000010 pkg=com.example.myapp cmp=com.example.myapp/com.google.android.gms.gcm.GcmReceiver (has extras) }, [email protected]
07-06 21:33:11.534 11269-11269/com.example.myapp D/ActivityThread: BDC-RECEIVER handled : 0/ReceiverData{intent=Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000010 pkg=com.example.myapp (has extras) } packageName=com.example.myapp resultCode=-1 resultData=null resultExtras=null}
07-06 21:33:11.539 11269-11269/com.example.myapp D/ActivityThread: SVC-Calling onStartCommand: [email protected], flags=0, startId=1
07-06 21:33:11.539 11269-11269/com.example.myapp D/ActivityThread: SVC-Creating service: CreateServiceData{[email protected] className=com.example.myapp.MyGcmListenerService packageName=com.example.myapp intent=null}
07-06 21:33:11.539 11269-11269/com.example.myapp D/ActivityThread: SVC-CREATE_SERVICE handled : 0/CreateServiceData{[email protected] className=com.example.myapp.MyGcmListenerService packageName=com.example.myapp intent=null}
07-06 21:33:11.543 11269-11269/com.example.myapp D/ActivityThread: SVC-SERVICE_ARGS handled : 0/ServiceArgsData{[email protected] startId=1 args=Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000010 pkg=com.example.myapp (has extras) }}07-06 21:33:11.565 11269-11269/com.example.myapp D/ActivityThread: SVC-Destroying service: [email protected]
07-06 21:33:11.565 11269-11269/com.example.myapp D/ActivityThread: SVC-STOP_SERVICE handled : 0/[email protected]
07-07 21:33:11.564 11269-11530/com.example.myapp D/MyGcmListenerService: bundle: Bundle[{key1=message1, key2=message2, notification=Bundle[{e=1, body=This is a notification that will be displayed ASAP., icon=ic_launcher, title=Hello, World}], collapse_key=com.example.myapp}]
07-06 21:33:11.564 11269-11530/com.example.myapp D/MyGcmListenerService: From: 28REDACTED98
07-06 21:33:11.564 11269-11530/com.example.myapp D/MyGcmListenerService: Message: null
我接收的代碼是:
public class MyGcmListenerService extends GcmListenerService {
public static final String TAG = MyGcmListenerService.class.getSimpleName();
@Override
public void onMessageReceived(String from, Bundle data) {
Log.d(TAG, "bundle: " + data);
String message = data.getString("message");
Log.d(TAG, "From: " + from);
Log.d(TAG, "Message: " + message);
...
發送代碼(使用節點-GCM)是:
var message = new ngcm.Message({
priority: 'high',
contentAvailable: true,
restrictedPackageName: "com.example.myapp",
data: {
key1: 'message1',
key2: 'message2'
},
notification: {
title: "Hello, World",
icon: "ic_launcher",
body: "This is a notification that will be displayed ASAP."
}
});
我已經有和沒有contentAvailable
和restrictedPackage
嘗試,但他們並不區別。
我的問題是:
- 如果我接收的代碼需要在消息到達創建屏幕上的通知,還是應該這(我相信)是對我由Android做了什麼?
- 示例代碼說該捆綁應該包含一個
data.getString("message");
,但我的應用程序將其視爲null。爲什麼?
要獲得自動創建的通知,你的推送消息必須遵循特定的消息格式,否則你必須創建它手動 –
@VivekMishra感謝您的信息。你能用一個具體格式的例子來寫答案嗎? – fadedbee