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

时间:2019-04-06 08:54:30

标签: android push-notification background foreground

在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。

1 个答案:

答案 0 :(得分:0)

您必须将Resultintent添加到PendingIntent,然后

要留意您的实际通知。

通过这种方式,您可以重定向到特定活动。