如何一点击通知就触发广播!?
问问题
239 次
1 回答
0
在 onMessage() 中扩展 GCMBaseIntentService 的类上调用 setNotificationMethod 如下
private void setNotification(int defaults, String message, int flag) {
NotificationManager mNotificationManager;
int MOOD_NOTIFICATIONS = 12345;
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// This method sets the defaults on the notification before posting it.
Intent handleNotification = new Intent(this, PushNotifier.class);
handleNotification.putExtra("Result", resultfrmServer);
// This is who should be launched if the user selects our notification.
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
handleNotification, PendingIntent.FLAG_UPDATE_CURRENT);
final Notification notification = new Notification(
R.drawable.ic_launcher, // the icon for the status bar
message, // the text to display in the ticker
System.currentTimeMillis()); // the timestamp for the
// notification
notification.setLatestEventInfo(this, // the context to use
getText(R.string.app_name),
// the title for the notification
message, // the details to display in the notification
contentIntent); // the contentIntent (see above)
notification.defaults = defaults;
notification.flags = flag;
mNotificationManager.notify(MOOD_NOTIFICATIONS,notification);
}
现在,当单击通知时,PushNotifier 类将启动。在这里,您可以决定是要启动其他活动还是注册广播接收器。此外,如果您需要在 pushnotification 中收到的信息,您可以相应地使用待处理的意图和用户将其发送到 pushNotifier 类。
于 2013-02-28T07:05:02.383 回答