当Android应用程序处于后台时,XMPP服务器正在向具有数据有效负载的主题发送通知。使用FCM通知的客户端Android应用程序也接收相同并显示横幅通知。
但是当我们尝试解析主要活动oncreate方法中的数据时,它显示Null.But我们的应用程序需要获取请求ID并在这种情况下打开相应的页面。
// getExtras not containing the notification data:
if (getIntent().getExtras() != null) {
for (String key : getIntent().getExtras().keySet()) {
String value = getIntent().getExtras().getString(key);
Log.d(TAG, "Key: " + key + " Value: " + value);
}
}
当Android应用程序在后台时,XMPP服务器正在发送以下数据
<message><gcm xmlns='google:mobile:data'>{"to":"/topics/xxxx","content_available":true,"collapse_key":"sample","delay_while_idle":true,"delivery_receipt_requested":true,"priority":"high","data":{"message":"{\n \"id\" : \"xxx\",\n \"reqId\" : \"1234\"},"time_to_live":10000,"notification":{"sound":"default"},"message_id":"685989336783482201"}</gcm></message>
Gradle依赖项:
classpath 'com.google.gms:google-services:3.0.0'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// SUB-PROJECT DEPENDENCIES START
debugCompile project(path: "CordovaLib", configuration: "debug")
releaseCompile project(path: "CordovaLib", configuration: "release")
// SUB-PROJECT DEPENDENCIES END
compile 'com.google.firebase:firebase-messaging:9.0.0'
}
apply plugin: 'com.google.gms.google-services'