Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.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 3.0-GCM不';t使用通知参数自动显示通知_Android_Notifications_Google Cloud Messaging - Fatal编程技术网

Android GCM 3.0-GCM不';t使用通知参数自动显示通知

Android GCM 3.0-GCM不';t使用通知参数自动显示通知,android,notifications,google-cloud-messaging,Android,Notifications,Google Cloud Messaging,新的GCM 3.0应该允许GCM自动显示从服务器发送的通知,如果它们包含通知参数 正如报告中所说: 带有预定义选项的通知参数表示,如果客户端应用在Android上实现GCMListenerService,GCM将代表客户端应用显示消息 然而,即使实现了GCMListenerService,我也很难让它正常工作 AndroidManifest.xml <receiver android:name="com.google.android.gms.gcm.GcmRecei

新的GCM 3.0应该允许GCM自动显示从服务器发送的通知,如果它们包含
通知
参数

正如报告中所说:

带有预定义选项的通知参数表示,如果客户端应用在Android上实现GCMListenerService,GCM将代表客户端应用显示消息

然而,即使实现了
GCMListenerService
,我也很难让它正常工作

AndroidManifest.xml

    <receiver
        android:name="com.google.android.gms.gcm.GcmReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="cz.kubaspatny.pushservertest" />
        </intent-filter>
    </receiver>

    <service
        android:name="cz.kubaspatny.pushservertest.gcm.CustomGcmListenerService"
        android:exported="false" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        </intent-filter>
    </service>
来自服务器的通知已记录,但GCM未显示

Received gcm from 333813590000 with bundle Bundle[{notification={"icon":"ic_launcher.png","body":"great match!","title":"Portugal vs. Denmark"}, collapse_key=do_not_collapse}]
从服务器发送的消息:

{       
      "registration_ids":[...],
      "data": {
        "notification" : {
            "body" : "great match!",
            "icon" : "ic_launcher.png",
            "title" : "Portugal vs. Denmark"
          }
      } 
}


是否需要执行其他操作以允许自动显示?

尝试将通知字段设置为数据字段的同级。数据字段传递给onMessageReceived,通知字段用于自动生成通知

{       
      "registration_ids":[...],
      "notification" : {
            "body" : "great match!",
            "icon" : "ic_launcher.png",
            "title" : "Portugal vs. Denmark"
      }

}

你在
通知
有效载荷中发送什么?@shkschneider编辑了这个问题。但是我正在发送
标题
正文
图标
您所说的“自动显示”是什么意思?@injecteer在i/O 15上说,如果GCM包含某些信息(标题、图标、文本),它将自动显示通知。或者如文档中所述,如果客户端应用程序实现了GCMListenerService,GCM将代表客户端应用程序显示消息,可能在即将发布的sdk中?
{       
      "registration_ids":[...],
      "notification" : {
            "body" : "great match!",
            "icon" : "ic_launcher.png",
            "title" : "Portugal vs. Denmark"
      }

}