我需要编写一些应用程序来在后台执行一些工作。此应用程序将从自动启动运行,不会有任何启动图形用户界面。 Gui 可以通过点击通知来调用,该通知将与自动启动一起显示。我担心,当用户清除通知时,他失去了调用此 gui 的机会。我的问题是有什么方法可以阻止用户清除我的通知吗?
最佳答案
这是一条不允许用户清除的通知。
Notification notification = new NotificationCompat.Builder(this)
.setTicker(r.getString(R.string.app_name))
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(r.getString(R.string.app_name))
.setAutoCancel(false)
.setOngoing(true)
.build();
setOngoing(true)
调用实现了这一点,当用户点击通知时,setAutoCancel(false)
阻止通知消失。
如果应用程序被卸载或通过调用 Cancel 或 CancelAll 将清除通知:http://developer.android.com/reference/android/app/NotificationManager.html#cancel(int)
关于android - 为我的应用程序禁用清除通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6966216/