![](/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.