为什么我的通知会被清除?

时间:2017-01-01 14:45:50

标签: android

我已经尝试了.setAutoCancel(false) and .setOngoing(true);,但为什么在刷卡时我的通知仍然被清除?这是我的代码 -

        Notification.Builder builder = new Notification.Builder(this)
            .setSmallIcon(R.drawable.download)
            .setContentTitle("Download[ROOT]")
            // .setContentText("This is a test notification")
            .setAutoCancel(false).setOngoing(true);
    Intent notificationIntent = new Intent(this, DownloaderRoot.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(contentIntent);
    // Add as notification
    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify(111, builder.build());

我也试过添加标志 -

// Add as notification
        NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notif = builder.build();// add flag support
        notif.flags |= Notification.FLAG_ONGOING_EVENT;
        notif.flags |= Notification.FLAG_NO_CLEAR;
        manager.notify(111, builder.build());

1 个答案:

答案 0 :(得分:0)

试试这个

Notification notif = builder.build();
notif.flags |= Notification.FLAG_ONGOING_EVENT;
manager.notify(111, notif);