Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 未显示GCM通知_Android_Google Cloud Messaging - Fatal编程技术网

Android 未显示GCM通知

Android 未显示GCM通知,android,google-cloud-messaging,Android,Google Cloud Messaging,我正在尝试使用该功能,当android自动显示接收推送消息的通知时,如所述 当我将notification字段添加到我的JSON负载时,通知似乎不仅没有显示,而且根本没有触发onMessageReceived。没有这个字段,一切都会好起来。 这里是我的json负载: { "to":"APA91bGIe59H1V5SsQkKvDOTgCTEaZWwgCJrdQ...", "message_id":"", &quo

我正在尝试使用该功能,当android自动显示接收推送消息的通知时,如所述
当我将
notification
字段添加到我的JSON负载时,通知似乎不仅没有显示,而且根本没有触发
onMessageReceived
。没有这个字段,一切都会好起来。
这里是我的json负载:

{
 "to":"APA91bGIe59H1V5SsQkKvDOTgCTEaZWwgCJrdQ...",
 "message_id":"",
 "notification":{
                 "body":"Notification test",
                 "title":"Notification header",
                 "icon":"noti.png"
                },
 "data":{
         "test_message":"GCM test message!"
        }
}
那么,为什么会发生这种情况?或者没有自动通知?(什么是
通知
字段,如果是……如果我必须自己生成通知,我可以使用
数据
字段)

编辑:
终于成功了。图标字段应类似于
“icon”:“@drawable/noti”


谷歌文档错误真的很烦人。

在我的例子中,通知没有显示,因为我在生成通知时没有设置通知项。 该建筑商的工作:

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_stat_ic_notification)
                .setContentTitle("GCM Message")
                .setContentText(message)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);

您需要将通知放在数据对象中。@Prokash为什么文档中说使用单独的字段?不管怎么说,没用。消息按预期传递,但没有通知。@StenSoft是和是,我使用的是最新的谷歌示例“图标”:“noti”也应按照文档中的说明工作:“指示通知图标。在Android上:为可绘制资源myicon.png设置myicon值。”如果您发布日志猫中显示的消息,此问题将在之前得到诊断。。。。