【发布时间】:2018-10-11 16:15:48
【问题描述】:
我正在制作一个通过蓝牙与 Aurdino 通信的应用程序。它使用通信部分的服务。因此,只要服务正在运行,我希望应用程序显示通知。用户不应该能够滑动通知以使其消失。
到目前为止,这是我的通知功能:
void showNotification(String title, String contentText)
{
...
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext(), "default")
.setSmallIcon(R.mipmap.ic_launcher) // notification icon
.setContentTitle(title) // title for notification
.setContentText(content)
.setAutoCancel(false)
.setOngoing(true);
mNotificationManager.notify(0, mBuilder.build());
}
请注意,我已经调用了setOngoing(true),但我仍然可以从通知抽屉中滑动通知,并且当我这样做时它会消失。
如何防止用户滑动和取消通知?我的应用程序在终止时会自动取消它,在服务的OnDestroy() 中。
【问题讨论】:
标签: android notifications persistent