gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 00:11:49 26 4
gpt4 key购买 nike

这是我的源代码。我需要,让它不可删除 - 它应该在点击后删除,而不是通过在通知管理器中滑动。是否可以?

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);
}`

最佳答案

您需要使用 setOngoing(true)使用您的 Notification.Builder:

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 (e.g., playing music) or is pending in some way and therefore occupying the device (e.g., a file download, sync operation, active network connection).

关于java - 如何创建不可删除的通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48026747/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com