2011-06-30 11 views
5

サービス開始時に通知を作成しましたが、サービスの停止または破棄時に通知を閉じる方法がわかりません。何か考えがある。閉じるアンドロイド通知

サービス開始時に通知を開始するコードに従います。あなたの通知IDを持つ

String ns = Context.NOTIFICATION_SERVICE; 
    final int KEEPUS_NOTIFICATION_ID = 1; 
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns); 
    Notification notification = new Notification(R.drawable.notification_icon1, ticker_text, System.currentTimeMillis()); 
    Intent notificationIntent = new Intent(context, KeepusActivity.class); 
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); 
    notification.setLatestEventInfo(context, ticker_content_title, ticker_content_text,contentIntent); 
    mNotificationManager.notify(KEEPUS_NOTIFICATION_ID, notification); 

答えて

21

使用通知マネージャ#cancel

NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
mNotificationManager.cancel(KEEPUS_NOTIFICATION_ID); 
関連する問題