配置在后台单击FCM推送 [英] Configure click on the FCM push in the background
问题描述
我无法使用FCM click_action启动后台活动.
I'm having trouble starting a background activity using FCM click_action.
我的宣言:
<activity
android:name="com.myoro.MainActivity"
android:theme="@style/AppTheme.NoActionBar"/>
<activity
android:name="com.myoro.ActivityA"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="com.myoro.A" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.myoro.ActivityB"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="com.myoro.B" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
我的消息设置:
data: {{"type" : "A","id" : "a123","click_action": "com.myoro.A"}}
JAVA:
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
if (remoteMessage.getData().size() > 0) {
if (remoteMessage.getData().containsKey("click_action")) {
Intent intent = new Intent(remoteMessage.getData().get("click_action"));
intent.putExtra("id", remoteMessage.getData().get("id"));
startActivity(intent);
return;
}
if (remoteMessage.getData().containsKey("data")) {
String data = remoteMessage.getData().get("data");
Gson gson = new Gson();
MyObj myObj = gson.fromJson(data, MyObj.class);
if(myObj.getType().equals("A")) {
Intent intent = new Intent(context, ActivityA.class);
intent.putExtra("id", myObj.getId());
startActivity(intent);
} else {
Intent intent = new Intent(context, ActivityB.class);
intent.putExtra("id", myObj.getId());
startActivity(intent);
}
}
}
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
}
如果我尝试发送此json模型,并且它始终打开活动主体.我该如何在fourground和背景中操纵通知单击以打开ActivityA和ActivityB并需要传递ID?...
In case I am trying to send this json model and it is always opening the activity main. How can I manipulate the notification click in fourground and background to open the ActivityA and ActivityB and need to pass the id?...
推荐答案
click_action
是应在notification
消息有效负载内使用的参数,而不是 not data
.
click_action
is a parameter that should be used inside a notification
message payload, not data
.
尝试将您的有效负载编辑为以下内容:
Try to edit your payload to something like:
}
notification:{
"click_action": "com.myoro.A"
},
data: {
"type" : "A",
"id" : "a123"
}
}
请参阅FCM HTTP参数以供参考: https://firebase.google.com/docs/cloud-messaging/http-server-ref
See the FCM HTTP parameters for reference: https://firebase.google.com/docs/cloud-messaging/http-server-ref
这篇关于配置在后台单击FCM推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!