我正在使用以下代码在我的 Android 手机上显示通知。我想减少用于显示通知的时间。现在,显示大约需要 2 秒,然后隐藏。我想将时间从 2 秒减少到 1 秒。可能吗?
Notification notification = new NotificationCompat.Builder(context)
.setContentTitle(context.getString(R.string.app_name))
.setContentText("Notification")
.setAutoCancel(false)
.setPriority(Notification.PRIORITY_MAX)
.setSmallIcon(R.mipmap.ic_launcher)
.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))
.build();
NotificationManager notificationManager = getNotificationManager(context);
notificationManager.notify(SAFER_DISCONNECTED_NOTIFICATION_ID, notification);
最佳答案
Now, it spends about 2 seconds for showing, then it is hidden.
对于 Notification
将在单挑模式下显示的时间量没有特别保证,我假设这就是您所指的。
例如,默认情况下它会在 Android 4.4 及更早版本上显示 0 秒,Android 4.4 及更早版本本身不支持抬头通知。但是,用户可以安装带有 NotificationListenerService
的应用程序,并且该服务可以显示通知,但显示时间不限。
Is it possible?
不,对不起。这是在显示通知的代码的控制下。
关于android - 是否可以减少 Android 中显示的通知时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40762621/