Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call activity when on notification tap event

I want to call the activity when user pull down the notification and tap on that notification. How can I do that?

like image 704
Kandha Avatar asked Sep 08 '10 09:09

Kandha


People also ask

How send parameters from notification click to activity in Android?

This example demonstrate about How to send parameters from a notification-click to an Android activity. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How do I handle click notifications?

You can show your custom Notification with PendingIntent. In the PendingIntent you can put activity that must be opened with needed data. Then when user click on the notification the activity with data will be opened. Again you'll get all needed data in the intent.

What is pending intent in notification?

In other words, PendingIntent lets us pass a future Intent to another application and allow that application to execute that Intent as if it had the same permissions as our application, whether or not our application is still around when the Intent is eventually invoked.


2 Answers

Call setLatestEventInfo() on the Notification object, supplying a PendingIntent that will start your activity when they tap on your entry in the notification drawer. Here is a sample project demonstrating this.

like image 154
CommonsWare Avatar answered Oct 08 '22 01:10

CommonsWare


Assuming that notif is your Notification object:

Intent notificationIntent = new Intent(this.getApplicationContext(), ActivityToStart.class);
PendingIntent contentIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, notificationIntent, 0);
notif.contentIntent = contentIntent;
like image 29
DonGru Avatar answered Oct 08 '22 00:10

DonGru