FCM通知click_action无法正常工作

Bad*_*adr 4 android firebase firebase-cloud-messaging

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

这是我在Web服务中使用的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"
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的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;
            }
Run Code Online (Sandbox Code Playgroud)

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

请注意,当应用程序处于前台时,它可以正常工作,但当应用程序处于后台时,它无法正常工作.

Rjz*_*ara 8

确保在Manifest文件中的CustomerRebateConfirmation活动中添加了这一行...

<intent-filter>
     <action android:name=".Activities.CustomerRebateConfirmation" />
     <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)