答案 0 :(得分:1)
使用标志Notification.FLAG_AUTO_CANCEL
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);
答案 1 :(得分:1)
如果您希望在用户点击后关闭通知,您可以在通知构建器中指定此标志:
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
//other flags
.setAutoCancel(true);
其他选项是通过代码取消通知:
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancel(NOTIFICATION_ID);
答案 2 :(得分:0)
只需设置一个标志
notification.flags |= Notification.FLAG_AUTO_CANCEL;
答案 3 :(得分:0)
IntentFilter filter = new IntentFilter(CONSTANT_MOTION_NOTIFICATION);
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);
创建一个本地广播接收器onReceive调用欲望活动并从notificationmanager调用cancelAll()