my question for you is the following: I have a web app written in HTML5, wrapped as a native Android app in order to use Google Push Notifications. Because my app is using many notifications for different reasons, I want to be able to say each time a notification is received, which page to be open, like adding a 'href' in the notification intent. Is this possible? If I wasn't clear enough please let me know. Thanks
Asked
Active
Viewed 714 times
2 Answers
0
You can define your own notification message content. The Message builder from Google supports key value pairs to be set by the sender of the notification. See http://developer.android.com/reference/com/google/android/gcm/server/Message.html
Example:
Message message = new Message.Builder()
.addData("link1", "http://mypage1.com")
.addData("link2", "http://mypage2.com")
.build();

userM1433372
- 5,345
- 35
- 38
-
I am already using this so I can know every notification arriving what type is it. But once the notification arrives, I don't know how I open a certain webview of my app. I suppose there's something to do with the Intent object, I'm still searching. – Alex Apr 03 '13 at 12:35
-
You can start the Android browser with the url or start your own activity containing a webview. See http://stackoverflow.com/questions/2201917/how-can-i-open-a-url-in-androids-web-browser-from-my-application – userM1433372 Apr 04 '13 at 14:20
0
When you create the notification, use setContentIntent() to attach an Intent that has been constructed to visit the right webpage:
// assuming <this> is an Activity or other Context
Intent urlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(yourUrl));
PendingIntent urlPendingIntent = PendingIntent.getActivity(this, 0 urlIntent, 0);
Notification.Builder b = new Notification.Builder(this)
.setSmallIcon(...).setContentTitle(...).setContentText(...) // etc.
.setContentIntent(urlPendingIntent);
NotificationManager noMan
= (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
noMan.notify(ID, b.build());
If you expect to have more than one of these in the notification panel at a time:
- Reconsider. It's spammy to post more than one notification.
- If you must, you'll need a separate ID (or separate tag) for each.

dsandler
- 2,471
- 17
- 11