gpt4 book ai didi

android - FCM 通知 click_action 不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:48:25 24 4
gpt4 key购买 nike

我对 FCM 有疑问,当我收到通知时,我希望它打开特定 Activity ,默认情况下,当我不添加 click_action 时,它会打开应用程序的主要 Activity ,但是当我添加 click_action 并点击通知时,它不会执行任何操作。

这是我在网络服务中使用的 JSON:

{
"registration_ids": [
"f4............LL"
],
"notification": {
"title": "Rebate Confirmation",
"text": "Please Confirm",
"sound": "default",
"click_action": ".Activities.CustomerRebateConfirmation"
},
"data": {
"merchant_id": "20",
"customer_id": "1",
"points": "10",
"totalpoints": "100",
"message": "Please Confirm",
"type": "customer_points_rebate_confirmation"
}
}

这是我的onMessageReceived 方法:

public void onMessageReceived(RemoteMessage remoteMessage) {

Log.e(TAG, "From: " + remoteMessage.getFrom());
customerRebateDetails = new String[5];

// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.e(TAG, "Message data payload: " + remoteMessage.getData());
Log.e(TAG, "Message notification: " + remoteMessage.getNotification().getBody());

String type = remoteMessage.getData().get("type");
String message = remoteMessage.getData().get("message");
String text = remoteMessage.getNotification().getBody();
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

switch (type){
case "customer_points_rebate_confirmation":
customerRebateDetails[0] = remoteMessage.getData().get("customer_id");
customerRebateDetails[1] = remoteMessage.getData().get("merchant_id");
customerRebateDetails[2] = remoteMessage.getData().get("points");
customerRebateDetails[3] = remoteMessage.getData().get("totalpoints");
Intent customerRebate = new Intent(this, CustomerRebateConfirmation.class);
customerRebate.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
customerRebate.putExtra("customer_points_rebate_confirmation", customerRebateDetails);
PendingIntent customerRebatePendingIntent = PendingIntent.getActivity(this, 0, customerRebate,
PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder customerRebateBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(message)
.setContentText(text)
.setSound(defaultSoundUri)
.setAutoCancel(true)
.setContentIntent(customerRebatePendingIntent);
NotificationManager customerRebateManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
customerRebateManager.notify(0, customerRebateBuilder.build());
break;
}

有谁知道实现的问题是什么?

请注意,当应用程序处于前台时它运行良好,但当应用程序处于后台时它不起作用。

最佳答案

确保您已将此行添加到 list 文件中的 CustomerRebateConfirmation Activity 中...

<intent-filter>
<action android:name=".Activities.CustomerRebateConfirmation" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

关于android - FCM 通知 click_action 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43372117/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com