我想顯示正在進行的通知。但它仍然顯示在通知部分。 我爲我的通知使用了自定義佈局。通知將不會「正在進行中」
這裏是我的代碼:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int icon = android.R.drawable.alert_dark_frame;
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, "Hi", when);
RemoteViews contentView = new RemoteViews(getPackageName(),
R.layout.custom_notification);
notification.contentView = contentView;
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
notification.contentIntent = contentIntent;
notification.defaults |= Notification.FLAG_ONGOING_EVENT;
mNotificationManager.notify(0, notification);
}
編輯: 你可以看到這個圖片,看看我想做的事情。 http://backcountrynavigator.com/wp-content/uploads/screenshots/download_ongoing_notification.png
標記爲「正在進行的事件」的通知仍然是通知。這就是它出現在通知列表中的原因。這基本上是一個粘性通知,無法使用清除按鈕從列表中清除。 – tiguchi
你是什麼意思「但它仍然顯示在通知部分」。你不希望它有通知顯示在那裏嗎? –
@NobuGames我認爲這是Notification.FLAG_NO_CLEAR,使通知unclerable。 –