【问题标题】:How to control frequency of notification update on locked screen如何控制锁定屏幕上通知更新的频率
【发布时间】:2017-06-02 21:20:57
【问题描述】:

我有一个通过服务更新通知的应用程序。

此通知每秒更新一次。它显示了一个计时器。

目前在牛轧糖上,设备锁定,通知更新触发屏幕唤醒,显示更新的通知。

我想控制它,因为我的通知非常频繁。

我还想避免更改通知的更新频率。这样做会向用户显示不太准确的信息。

所以我正在寻找一种编程方式来控制通知更新时的唤醒屏幕频率。

谢谢你:)

【问题讨论】:

  • 我不确定你是否可以控制“唤醒屏幕频率”,但你为什么不在更新通知之前检查屏幕是否打开?屏幕关闭时更新通知没有任何意义。检查here以检查屏幕是打开还是关闭。
  • @Swordsman 听起来是个好主意,我会尝试并告诉你。

标签: android notifications android-notifications


【解决方案1】:

以下通知可用于频繁更新用户,并且屏幕在锁定时不会唤醒。你可以试试

if(notificationBuilder == null) {
             notificationBuilder =
                     new NotificationCompat.Builder(MainActivity.this)
                             .setSmallIcon(R.mipmap.ic_launcher)
                             .extend(wearableExtender)
                             .setAutoCancel(true)
                             .setContentTitle("Random Notification")
                             .setContentText("Appears!")
                             .setOnlyAlertOnce(true)
                             .setOngoing(true)
                             .setVisibility(Notification.VISIBILITY_PUBLIC)
                             .setContentIntent(contentIntent);
         }else{
             notificationBuilder.setContentText("change this to current updated text");
         }
            NotificationManagerCompat notificationManager = NotificationManagerCompat.from(MainActivity.this);

            notificationManager.notify(888, notificationBuilder.build());

【讨论】:

  • 谢谢。我试过了,但它不起作用。通知来自前台服务。所以我从 startForeground 开始。我不知道这是否有区别。您是否测试过您的解决方案?
  • 是的,我每秒都会发布一个通知,通知 ID 相同,并且使用相同的通知生成器。锁定时手机没有唤醒。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多