0

Is it possible to prohibit opening an activity with the notification by the FCM server?

I'm talking about the notification sent via the manifest

If the user clicks the notification, by default it open MainActivity.

I just want it to disappear and not open any activity

I try this but not work :

 // [START handle_data_extras]
    if (getIntent().getExtras() != null) {
        for (String key : getIntent().getExtras().keySet()) {
            Object value = getIntent().getExtras().get(key);
            Log.d("TAG", "Key: " + key + " Value: " + value);

           if (value.equals(myValue)) {
                Toast.makeText(this, "Close", Toast.LENGTH_SHORT).show();
                finish();
            }

        }

Temporary solution :

open an activity that closes all :

  if (getIntent().getExtras() != null) {
             for (String key : getIntent().getExtras().keySet()) {
                 Object value = getIntent().getExtras().get(key);
                 Log.d("TAG", "Key: " + key + " Value: " + value);
                 if (value.equals(myvaluefirebase)) {
                     Log.d("TAG", "Key value it's OK");
                     Intent mainIntent = new Intent(SplashActivity.this, **Close.class)**;
                     startActivity(mainIntent);
                     SplashActivity.this.finish();
                     finish();
                 }
             }}
Croid
  • 109
  • 5
  • I found this post, it is not possible with the payload : https://stackoverflow.com/questions/53129669/desired-activity-not-open-while-clicking-on-notification-fcm – Croid Apr 08 '20 at 09:02

1 Answers1

0

Set the pending intent like that

PendingIntent pendingIntent  = PendingIntent.getActivity(this, 0, new Intent(), 0);
            builder.setContentIntent(pendingIntent);

Also enable setAutoCancel()

  builder.setAutoCancel(true);
Usman Zafer
  • 1,027
  • 1
  • 8
  • 11