I am a huge noob for Android programming, so sorry if this is a simple task. I pretty much followed the Vogella push notification guide for push notifications (http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html). I read some other stack overflow issues, but I'm a little confused about how to open an intent after receiving a notification.
For example, if I just want a notification to lead me to a website, how will it work? Should it be with my MessageReceivedActivity or another project / class?
thank
Here is the code that I have for my C2DMMessageReceiver
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.w("C2DM", "Message Receiver called");
if ("com.google.android.c2dm.intent.RECEIVE".equals(action)) {
Log.w("C2DM", "Received message");
final String payload = intent.getStringExtra("payload");
Log.d("C2DM", "dmControl: payload = " + payload);
createNotification(context, payload);
}
}
public void createNotification(Context context, String payload) {
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher,
"Message received", System.currentTimeMillis());
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_LIGHTS;
Intent intent = new Intent(context, MessageReceivedActivity.class);
intent.putExtra("payload", payload);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
intent, 0);
notification.setLatestEventInfo(context, "Message",
"New message received", pendingIntent);
notificationManager.notify(0, notification);
}
}
source
share