![](/img/trans.png)
[英]How to close the status bar/notification panel after notification button click
[英]Close Status Bar after Notification click
我的通知包含几个按钮:
问题是,第一个按钮没有关闭状态栏...
第一个按钮发送的PendingIntent:
Intent activityIntent = new Intent(smp, MusicShaker.class)
.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
activityIntent.setAction(MyIntentAction.DO_LAUNCH_ACTIVITY_FROM_NOTIF);
remoteViews.setOnClickPendingIntent(R.id.notif_album_IV, PendingIntent
.getActivity(ctxt, 0, activityIntent,
PendingIntent.FLAG_CANCEL_CURRENT));
活动已正确启动,但状态栏保持不变并且不会自行关闭。
我错过/误会了一面旗帜吗? 我可以从MyActivity.onResume()关闭状态栏progamaticaly吗?
编辑:顺便说一下,通知是由服务推送的
谢谢=)
您,只需要在创建构建器时指定setAutoCancel(true)。 这就是全部:)
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("title goes here")
.setContentText("content text goes here").setAutoCancel(true);
是的,您必须在应用启动时以编程方式取消通知。
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(NOTIFICATION_ID);
好的,我找到了一个解决方案......我无法重现标准通知产生的相同行为,所以我:
- 使我的imageButton“notif_album_IV”无法点击,并将其更改为ImageView
- 使用此代码:
builder.setContentIntent(PendingIntent.getActivity(smp, 0,
activityIntent,PendingIntent.FLAG_CANCEL_CURRENT))
而不是在图像上“手动”设置setOnClickPendingIntent,意图广播由内容背景处理
这对我有用:
sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.