[英]Close Status Bar after Notification click
My notification contains several buttons : 我的通知包含几个按钮:
The problem is, the first button does not close the status bar... 问题是,第一个按钮没有关闭状态栏...
the PendingIntent sent by the first button : 第一个按钮发送的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));
the activity is correctly launched, but the status bar stays there and does not close itself. 活动已正确启动,但状态栏保持不变并且不会自行关闭。
Am I missing/misunderstanding a flag ? 我错过/误会了一面旗帜吗? can I close the status bar progamaticaly from MyActivity.onResume() ?
我可以从MyActivity.onResume()关闭状态栏progamaticaly吗?
edit: by the way, the notification is pushed by a service 编辑:顺便说一下,通知是由服务推送的
thanks =) 谢谢=)
You, just need to specify setAutoCancel(true) while creating builder. 您,只需要在创建构建器时指定setAutoCancel(true)。 And that is all :)
这就是全部:)
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("title goes here")
.setContentText("content text goes here").setAutoCancel(true);
Yeah, you'll have to cancel the notification programmatically when your app starts. 是的,您必须在应用启动时以编程方式取消通知。
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(NOTIFICATION_ID);
ok, I found a solution... I could not reproduce the same behavior produced by standard notification, so I : 好的,我找到了一个解决方案......我无法重现标准通知产生的相同行为,所以我:
- made my imageButton "notif_album_IV" non clickable, and change it to an ImageView - 使我的imageButton“notif_album_IV”无法点击,并将其更改为ImageView
- used this code : - 使用此代码:
builder.setContentIntent(PendingIntent.getActivity(smp, 0,
activityIntent,PendingIntent.FLAG_CANCEL_CURRENT))
instead of setting the setOnClickPendingIntent "manually" on the image, the intent broadcast is handled by the content background 而不是在图像上“手动”设置setOnClickPendingIntent,意图广播由内容背景处理
这对我有用:
sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.