简体   繁体   English

如何创建不可删除的通知?

[英]How can I create undeletable notifications?

this is my source code.这是我的源代码。 I need, to make it undeletable - it should be delete after click on that, not by swiping in the notification manager.我需要,使其不可删除 - 它应该在点击后删除,而不是通过在通知管理器中滑动。 Is it possible?是否可以?

Intent intent = new Intent(this, SecondActivity.class); intent.putExtra("NotiClick", true); PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
        Notification Noti;
        Noti = new Notification.Builder(this)
                .setContentTitle("Dont Lose It")
                .setContentText("Stop monitoring by click!")
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentIntent(pIntent)
                .setAutoCancel(true).build();

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        notificationManager.notify(0, Noti);
    }`

You need to use setOngoing(true) with your Notification.Builder :您需要在Notification.Builder使用setOngoing(true)

Set whether this is an "ongoing" notification.设置这是否是“正在进行的”通知。 Ongoing notifications cannot be dismissed by the user, so your application or service must take care of canceling them.用户无法取消正在进行的通知,因此您的应用程序或服务必须注意取消它们。 They are typically used to indicate a background task that the user is actively engaged with (eg, playing music) or is pending in some way and therefore occupying the device (eg, a file download, sync operation, active network connection).它们通常用于指示用户正在积极参与(例如,播放音乐)或以某种方式挂起并因此占用设备(例如,文件下载、同步操作、活动网络连接)的后台任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM