我已經搜索了相當一段時間了,但是我無法找到答案。我的應用程序顯示通知Notification.PRIORITY_HIGH
,導致它顯示爲棒棒糖上的單挑通知。棒棒堂:單擊時取消單挑通知
的問題是,點擊通知本身時(即推出了contentIntent
)通知被自動清除,即使Notification.FLAG_AUTO_CANCEL
是不集和通知有Notification.FLAG_NO_CANCEL
集。我試過各種標誌組合,包括Notification.FLAG_ONGOING_EVENT
,但行爲保持不變。
我希望通知成爲'正常'的通知,而不是取消...任何想法如何解決這個問題?該文檔是不是在這個問題上完全清楚......
代碼重現:
private void showHeadsUpNotification()
{
final Notification.Builder nb = new Notification.Builder(this);
nb.setContentTitle("Foobar");
nb.setContentText("I am the content text");
nb.setDefaults(Notification.DEFAULT_ALL);
nb.setOngoing(true);
nb.setSmallIcon(android.R.drawable.ic_dialog_info);
nb.setContentIntent(PendingIntent.getActivity(this, 0, getIntent(), 0));
// Commenting this line 'fixes' it by not making it heads-up, but that's
// not what I want...
nb.setPriority(Notification.PRIORITY_HIGH);
((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(0, nb.build());
}
編輯:我注意到,當應用程序發佈的通知是在前臺,通知成爲一個正常的,就像我所期望的那樣。輕掃單挑通知(無論當前的前臺應用程序)是否也會生成常規通知。
我其實更喜歡的通知不被單挑所有,但在同一時間,我想保留'PRIORITY_HIGH'。由於聲音和/或振動也需要通知成爲單挑,我的方法就是禁用第二次通知。這樣,它的'PRIORITY_HIGH',但不是單挑。 – caspase 2014-12-03 16:09:53