'Android Studio: How to get information from notification intents?

I have a notification from a Foreground Service, this notification has two intents that shows the app/activity, but one of this intent also request the activity to execute some code, BUT I can't differentiate between these intents!!

NOTICATION

        Bundle extras1 = new Bundle();
        extras1.putString(NotificationReceiver.REQUEST,NotificationReceiver.ACTIVITY);
        Intent showAppIntent = new Intent(this, MainActivity.class)
            .putExtras(extras1)
            .setAction(Intent.ACTION_MAIN)
            .setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
        pendingShowAppIntent = PendingIntent.getActivity(this,
                0, showAppIntent, 0);

        Bundle extras2 = new Bundle();
        extras1.putString(NotificationReceiver.REQUEST,NotificationReceiver.ADD_EVENT);
        Intent addEventIntent = new Intent(this, MainActivity.class)
            .putExtras(extras2)
            .setAction(Intent.ACTION_CALL_BUTTON)
            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        pendingAddEventIntent = PendingIntent.getActivity(this,
                0, addEventIntent, 0);

       ...

       expandedView = new RemoteViews(getPackageName(),R.layout.notification_expanded);
       expandedView.setOnClickPendingIntent(R.id.ivNotificationEquipment,pendingAddEventIntent);
        Notification notification = new NotificationCompat.Builder(context, APP.CHANNEL_ID)
        .setContentTitle("Fishing Tracker")
        .setCustomContentView(expandedView)
        .setCustomBigContentView(expandedView)
        .setContentText("no text")
        .setSmallIcon(R.drawable.go_fishing_black)
        .setContentIntent(pendingShowAppIntent)
        .setPriority(NotificationCompat.PRIORITY_HIGH)
        .setOnlyAlertOnce(true)
        .build();

ACTIVITY

    @Override
    protected void onStart() {
        super.onStart();
        DftOp.showMessageLong(getIntent().getAction()+" - "+getIntent().getFlags()+" - "+getIntent().getStringExtra(NotificationReceiver.REQUEST));
    }

BUT THE RESULT of getIntent is ALWAYS THE SAME: Action = ...Main - Flags = 270532608 - Request = null !!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source