未从android中的notificationbar中删除Pushnotification
在我的应用程序中,我收到了来自gcm的推送通知,如果我单击该推送通知,我的应用程序将打开,我需要从通知栏中删除我的通知。但是,它仍然在通知栏上 我使用以下逻辑在gcminentservice类中生成推送通知未从android中的notificationbar中删除Pushnotification,android,push-notification,google-cloud-messaging,Android,Push Notification,Google Cloud Messaging,在我的应用程序中,我收到了来自gcm的推送通知,如果我单击该推送通知,我的应用程序将打开,我需要从通知栏中删除我的通知。但是,它仍然在通知栏上 我使用以下逻辑在gcminentservice类中生成推送通知 mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); //PendingIntent
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
//PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, TipsActivity.class), 0);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, TipsActivity.class),
Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.icon)
.setContentTitle("Appname")
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setContentText(msg);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
所以,当我点击我的通知时,请指导我如何删除它。根据我的猜测,它是由于通知标志而发生的 您的代码中可能有一行与通知标志相关 可能标志是
flag\u NO\u CLEAR
,因此将该标志更改为flag\u AUTO\u CANCEL
您将在generateNotification logic中找到该标志,如果您未提及该标志,请将其指定为flag_AUTO_CANCEL
标志\u否\u清除表示
如果用户单击“全部清除”按钮时不应取消通知,则应在标志字段中设置按位或按位的位
及
标记自动取消意味着
位按位或入标志字段,如果用户单击通知时应取消通知,则应设置该字段
这是样品线
notification.flags |= Notification.FLAG_AUTO_CANCEL;
其中,通知是通知管理器的对象
使用链接进行参照
希望它能解决您的问题。您必须添加以下行>
mBuilder.setAutoCancel(true);
试试这个,让我知道反馈