2011-11-09 23 views
0
私は ONGOING_EVENT作成するために、次のコードを持っている

隠す:今継続的な通知

Notification notification = new Notification(R.drawable.icon, "someText" , System.currentTimeMillis()); 
notification.flags |= Notification.FLAG_ONGOING_EVENT; 
notification.flags |= Notification.FLAG_FOREGROUND_SERVICE; 

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Home.class), 0); 
notification.setLatestEventInfo(this, "someTitle", "someText", contentIntent); 

notificationManager.notify(SOME_ID, notification); 

を、私は後でそれを殺したい:しかし

notificationManager.cancel(SOME_ID); 

を、通知が残ります。これの原因は何でしょうか?

+1

http://stackoverflow.com/questions/5232650/android-notification-deleteこれはあなたのポーズに役立つかもしれません。 – drooooooid

答えて

3

問題はnotification.flags |= Notification.FLAG_FOREGROUND_SERVICE;です。私はこのフラグのドキュメントを誤解し、その後通知を削除できませんでした。このフラグは、通常startForeground(int id, Notification notification)で始まるサービスによって設定され、サービスが停止するまで通知の削除を防止します(stopForeground(boolean removeNotification))。

ここではstartForeground/stopForegroundの方法を使用していますが、通知は完全に表示されています。

0

まだこのフラグは実装されていませんが、通知フラグFLAG_AUTO_CANCELを確認しています。通知を作成する前にこれを追加してください。

+0

これは、通知の詳細をアップロードするので、達成したいのではなく、ユーザーがクリックしたときに通知をキャンセルします。 – Femaref

関連する問題