android - 是否可以减少 Android 中显示的通知时间?

标签 android android-notifications android-notification-bar

我正在使用以下代码在我的 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/

相关文章:

Android 导航组件无法与对话框 fragment 一起使用

java - 如何在android O中使用通知 channel

android - 从状态栏中的扩展通知中获取文本?

android - 布局验证不同于加载程序 android Studio

android - 当 BLE 设备向 Android 手机发送数据时,如果应用程序未运行,如何在应用程序中获得通知

java - Android 中特定边邻接矩阵中的 Dijkstra 算法

android - 点击从 BroadcastReceiver 推送的通知时打开 Activity

android - 当应用程序处于后台时,我的 FCM 通知不会展开

android - 来自 Exoplayer PlayerNotificationManager 的多个频繁播放通知,用于使用 exoplayer2 播放的直播视频

android - 大通知图标旁边的灰色圆圈?