如何在通知Onclick android上进行特定活动?默认情况下,它会进入启动器活动/ MainActivity。这该怎么做?

问题描述 投票:0回答:1

点击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个回答
0
投票

你必须将Resultintent添加到PendingIntent然后

等待你的实际通知。

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

© www.soinside.com 2019 - 2024. All rights reserved.