我必须开发一个推送通知应用程序。
我确实喜欢:
@Override
protected void onMessage(Context context, Intent intent) {
Log.i(TAG, "Received message");
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
regId = GCMRegistrar.getRegistrationId(this);
String message = intent.getExtras().getString("offer");
displayMessage(context, message);
// notifies user
if(Constants.response != null){
generateNotification(context,message);
}
}
private static void generateNotification(Context context,String message) {
int icon = R.drawable.icon;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context, MyDealProducts.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);
}
此处通知已在登录客户中成功生成。
现在没有访问这些通知,同时注销了客户表单,这意味着我不需要启用通知。
但是这里通知已启用。如何在注销客户后禁用通知???
请给我一个建议???答案 0 :(得分:0)
为此,您可以在用户注销时取消您生成的通知。
使用方法cancel(int id)
(其中,id是通知ID,在您的情况下,是0
)或cancelAll()
NotificationManager
。