2 clcurie 11 clcurie_11 于 2013.06.21 10:02 提问

清除一个通知状态出现的问题

我不知道如何清除一个通知状态。

public void NotificationStatus(){
    Intent intent = new Intent(this, Stimulation.class);   
    NotificationManager notificationManager
        = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Notification notification = new Notification(
        david.flanagan.android.VenAssist.Activities.R.drawable.notification_icon,
        "VenAssist Stimulation ON", System.currentTimeMillis());
    PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 0);
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    notification.flags |= Notification.DEFAULT_VIBRATE;
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.setLatestEventInfo(this, "VenAssist",
        "Stimulation Started", activity);
    notificationManager.notify(0, notification);     
}

我想在服务器的onDestroy()函数中通过调用 notification.cancel(0);来清除通知状态。

我创建了一个通知的实例,不确定对不对。

private NotificationManager notification;

我想取消服务时,因此清除 status bar,程序就崩溃了。

1个回答

Jave_
Jave_   2013.06.21 10:19
已采纳

加上第一句试试:

 NotificationManager m_NotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    m_NotificationManager.cancel(0);
Csdn user default icon
上传中...
上传图片
插入图片