Android 如何在单击remoteview或操作按钮时清除自定义通知?

Android 如何在单击remoteview或操作按钮时清除自定义通知?,android,notifications,Android,Notifications,使用标志通知。标志自动取消 Notification notification = new Notification(icon, tickerText, when); notification.setLatestEventInfo(context, contentTitle, contentText, pendingIntent); // Cancel the notification after its selected notification.flags |= Notifica

使用标志通知。标志自动取消

Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, pendingIntent);

// Cancel the notification after its selected

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
要启动应用程序,请执行以下操作:

NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

// Create a new intent which will be fired if you click on the 

    notification
    Intent intent = new Intent(context, App.class);

// Attach the intent to a pending intent
PendingIntent pendingIntent = PendingIntent.getActivity(context, intent_id, intent, PendingIntent.FLAG_UPDATE_CURRENT);

如果希望在用户单击通知后关闭该通知,可以在通知生成器中指定此标志:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
        //other flags
        .setAutoCancel(true);
其他选项是通过代码取消通知:

NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancel(NOTIFICATION_ID);
只要插一面旗子就行了

notification.flags |= Notification.FLAG_AUTO_CANCEL;

IntentFilter filter=新的IntentFilter(持续运动通知)


从notificationmanager创建一个本地宽频广播接收器,接收所需的调用活动并调用cancelAll()

设置一个标记为ur notification notification.flags |=notification.flag_AUTO_CANCEL;
    final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context contextr, Intent intent) {
            Intent mute = new Intent(contextr, VideoActivity.class);
            mute.putExtra("url", "http://dev.galaxyweblinks.com/memorybadge/phase1/uploads/video/garage.mp4");
            contextr.startActivity(mute);
            notificationManager.cancelAll();
        }
    };
    context.registerReceiver(broadcastReceiver, filter);