Home > Software design >  pending intent in notification not working if app is open
pending intent in notification not working if app is open

Time:07-02

Please be informed we are sending push notification with a URl attached to pendingIntent for addAction button. AddAction button opens the mainactivity of app and directs to url in the webview. This sequence (pendingintent) works perfectly when app is closed, but when it is open, notification just stands there and opens the app in its already viewed page/activity rather than the new activity/page.

Our pendingIntent code is given below

int m = (int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE);
        int requestID = (int) System.currentTimeMillis();
        int notification_id=m;


        Intent intent = new Intent(this, MainActivity.class);
        intent.putExtra("uri", uri);
        intent.putExtra("notification_id", notification_id);
        /ntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, requestID, intent, PendingIntent.FLAG_UPDATE_CURRENT);

Please guide us as where we are going wrong.

CodePudding user response:

Try this

PendingIntent notifyPendingIntent = PendingIntent.getActivity(
    this, 0, notifyIntent,
    PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);

For more details

https://developer.android.com/training/notify-user/navigation

  • Related