Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open android app from PUSH notification

Got a little problem that's been bugging me..

I've set up my application to receive PUSH notifications from Urban Airship and that all works fine, but when I tap on a notification in the notifications center, nothing happens.

I want my app to open when a user taps a PUSH notification - what can I do to achieve this?

Any help is as always greatly appreciated.

Thanks

like image 254
PinkFloydRocks Avatar asked Feb 03 '23 06:02

PinkFloydRocks


2 Answers

Create a pending Intent to start the activity and set it in notification using setLatestEventInfo.

Example:

  Context context = getApplicationContext();
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";
Intent notificationIntent = new Intent(this, MyClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

More info can be found here

like image 125
San Avatar answered Feb 04 '23 19:02

San


You need to use a custom notification builder and use one of your activities as the PendingIntent.

https://docs.urbanairship.com/android-lib/reference/com/urbanairship/push/CustomPushNotificationBuilder.html

like image 21
smith324 Avatar answered Feb 04 '23 19:02

smith324