任何人都可以告诉我如何点击通知后立即触发广播!如果我得到一些关于相同的教程,那将会很棒。
答案 0 :(得分: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类。在这里,您可以决定是否要启动其他活动或注册广播接收器。此外,如果您需要在推送通知中收到信息,您可以使用待定意图和用户相应地将其发送到pushNotifier类。