[英]How can I create undeletable notifications?
這是我的源代碼。 我需要,使其不可刪除 - 它應該在點擊后刪除,而不是通過在通知管理器中滑動。 是否可以?
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);
}`
您需要在Notification.Builder
使用setOngoing(true) :
設置這是否是“正在進行的”通知。 用戶無法取消正在進行的通知,因此您的應用程序或服務必須注意取消它們。 它們通常用於指示用戶正在積極參與(例如,播放音樂)或以某種方式掛起並因此占用設備(例如,文件下載、同步操作、活動網絡連接)的后台任務。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.