Ali Ayasrah
Ali Ayasrah

Reputation: 75

click event on firebase notification android

about event for click on notification: I am searching since yesterday about that , what I found/understood: in FirebaseMessagingService will receive notification data , after will fire local notification, so need to add event in that local notification, I tried to add that many times with many ways but nothing worked … after I tried to deleted notification files (firebase notification files, and local notification files) but still can receive notification. do you know how to know if the user clicked on the notification ?

Upvotes: 0

Views: 1984

Answers (2)

JunaidKhan
JunaidKhan

Reputation: 744

Step 1:

// Create an Intent for the activity you want to start
Intent intent = new Intent(this, MainActivity.class);

Step 2:

// Create the PendingIntent
PendingIntent pendingIntent = PendingIntent.getActivity(this, Calendar.getInstance().get(Calendar.MILLISECOND),  intent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);

Step3:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID);
builder.setContentIntent(pendingIntent);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(NOTIFICATION_ID, builder.build());

Whenever a user clicks on notification MainActivity will be opened.

Here is details implementation of Android Notification Sample https://github.com/android/user-interface-samples/tree/master/Notifications

Upvotes: 0

mendax01
mendax01

Reputation: 31

To receive messages, use a service that extends FirebaseMessagingService. Your service should override the onMessageReceived and onDeletedMessages callbacks. It should handle any message within 20 seconds of receipt (10 seconds on Android Marshmallow). The time window may be shorter depending on OS delays incurred ahead of calling onMessageReceived. After that time, various OS behaviors such as Android O's background execution limits may interfere with your ability to complete your work.

For further info. you can visit the official website: Link: https://firebase.google.com/docs/cloud-messaging/android/receive

Hope you'll get your answer here.

Upvotes: 1

Related Questions