Android - 如何创建永久通知

时间:2014-03-21 10:18:29

标签: android notifications

我已经在我的" onCreate"中创建了一个通知活动方法。

一切运行顺利,只需按下"全部删除"按钮。

如何制作此通知perma?因为它应该只是一个信息而不是通知..

这是我目前的代码:

    private void showNotification() {
    // TODO Auto-generated method stub
    nMN = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Notification n  = new Notification.Builder(this)
    .setContentTitle("Whip And Weep")
    .setContentText("Whip is On!")
    .setSmallIcon(R.drawable.ic_launcher)
    .build();
    nMN.notify(NOTIFICATION_ID, n);
}

2 个答案:

答案 0 :(得分:21)

在通知构建器上使用.setOngoing(true)。这将阻止用户删除您的通知。

有关详细信息,请参阅Notification Builder文档: http://developer.android.com/reference/android/app/Notification.Builder.html#setOngoing%28boolean%29

答案 1 :(得分:5)

确定在您的代码中添加:

n.flags |= Notification.FLAG_NO_CLEAR;