【问题标题】:How to go specific activity on notification Onclick android? default it goes to launcher activity/ MainActivity. How to do this?如何在通知 Onclick android 上进行特定活动?默认它转到启动器活动/ MainActivity。这个怎么做?
【发布时间】:2023-08-03 23:18:01
【问题描述】:

点击 android 中的通知时,我无法进入特定活动。它总是在点击时转到启动器/MainActivity。

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    Log.e(TAG, "From: " + remoteMessage.getFrom());

    if (remoteMessage == null)
        return;

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.e(TAG, "Notification Body: " + remoteMessage.getNotification().getBody());
        handleNotification(remoteMessage.getNotification().getBody());
    }

    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        Log.e(TAG, "Data Payload: " + remoteMessage.getData().toString());

        String title=remoteMessage.getData().get("title");
        String message=remoteMessage.getData().get("body");
        String click_action=remoteMessage.getData().get("click_action");
        //System.out.println("clickAction=="+click_action);

        handleDataMessage(title,message,click_action);
 }
}


private void handleDataMessage(String noti_title,String noti_message,String noti_click_action) {

        String title = noti_title;
        String message = noti_message;
        String click_action = noti_click_action;


Intent resultIntent = null;

 if(click_action.equalsIgnoreCase("Coupon")){
                resultIntent = new Intent(getApplicationContext(), RewardActivity.class);

                resultIntent.putExtra("Activity","reward");
                startActivity(resultIntent);
            }else{
              resultIntent= new Intent(Config.PUSH_NOTIFICATION);
              resultIntent.putExtra("message", message);    
LocalBroadcastManager.getInstance(this).sendBroadcast(resultIntent);
            showNotificationMessage(getApplicationContext(), title, message, System.currentTimeMillis() + "", pushNotification);
            // play notification sound
            NotificationUtils notificationUtils = new NotificationUtils(getApplicationContext());
             notificationUtils.playNotificationSound();
}

当出现新的优惠券通知时,我想转到 RewardActivity 而不是启动器或 MainActivity。

【问题讨论】:

    标签: android push-notification background foreground


    【解决方案1】:

    你必须将 Resultintent 添加到 PendingIntent 然后

    等待您的实际通知。

    这样你可以重定向到特定的活动。

    【讨论】:

      最近更新 更多