I want to call the activity when user pull down the notification and tap on that notification. How can I do that?
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.
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.
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.
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With