在我的應用程序中,我添加了一個正在進行的通知。通知在狀態欄上有一個圖標,在通知區域有更多詳細信息。Android - 如何將狀態欄上的進行中的事件,但不通知屏幕上?
此圖片來自Google。這是在通知區域:
我需要在狀態欄上的圖標會在那裏住總,但用戶將能夠解僱通知屏幕的通知,以便用戶將與只停留狀態欄上的圖標。 我該怎麼辦?
我的服務代碼:
@SuppressWarnings("static-access")
@Override
public int onStartCommand(Intent intent, int flag, int startId)
{
super.onStartCommand(intent, START_STICKY, startId);
...
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setContentTitle(getString(R.string.myNotificationString))
.setContentText(string1 + " | " + string2)
.setLargeIcon(appIcon)
.setSmallIcon(getResources().getIdentifier("icon_" + getCurrentIconNumber(),"drawable", getPackageName())); // the icon changes every day
Intent resultIntent = new Intent(this, MainActivity.class);
PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0 ,resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
Notification notification = mBuilder.build();
notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.notify(myRequestCode, notification);
return START_STICKY;
}
抱歉,但我目前還不清楚我編輯的問題 – ddb
。簡而言之:假設我有一個應用程序向用戶顯示電池狀態。用戶希望在狀態欄上看到電池狀態,但他不想將其始終視爲通知區域中的通知。所以我希望用戶能夠關閉通知區域中的通知,但狀態欄上的圖標不會消失。 – TamarG
像鬧鐘主動通知?您可以刪除已設置鬧鐘的通知,但如果您將其刪除,您總是會在狀態欄中看到應用程序圖標。我明白了嗎? – ddb