android - 通知 setLights() 默认值?

标签 android notifications android-notifications

我想创建一个自定义通知。所以我想改变灯光和音调。 为此,我使用了 NotificationCompat.Builder

现在我想通过 setLights() 改变灯光; 工作正常。但我想设置 onMSoffMS 的默认值。我还没有找到相关信息。

谁能帮我找到默认值? 这是相关文档:http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setLights(int, int, int)

最佳答案

参见 Android source答案:

<!-- Default color for notification LED. -->
<color name="config_defaultNotificationColor">#ffffffff</color>
<!-- Default LED on time for notification LED in milliseconds. -->
<integer name="config_defaultNotificationLedOn">500</integer>
<!-- Default LED off time for notification LED in milliseconds. -->
<integer name="config_defaultNotificationLedOff">2000</integer>

然而,不同的 ROM 可能具有不同的值。例如,对于 config_defaultNotificationLedOff,我的返回 5000。所以你可能想在运行时获取它们:

Resources resources = context.getResources(),
          systemResources = Resources.getSystem();
notificationBuilder.setLights(
    ContextCompat.getColor(context, systemResources
        .getIdentifier("config_defaultNotificationColor", "color", "android")),
    resources.getInteger(systemResources
        .getIdentifier("config_defaultNotificationLedOn", "integer", "android")),
    resources.getInteger(systemResources
        .getIdentifier("config_defaultNotificationLedOff", "integer", "android")));

根据 diff ,这些属性保证存在于 Android 2.2+(API 级别 8+)上。

关于android - 通知 setLights() 默认值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15109593/

相关文章:

android - 通知 channel 错误

android - 在操作栏中添加一个下拉项目

java - 在处理 onPostExecute 之前等待其他 AsyncTasks 在 AsyncTask 中完成

notifications - Jira 通知与 Skype 集成

java - 应用程序崩溃: Attempt to invoke virtual method on a null object reference

android - 杀死 Activity 的所有实例

java - Android根据坐标高亮显示Imageview区域

java - java中是否可以回调外部嵌套类?

java - 如何在firestore android studio中获取新添加数据的通知?

java - Android 多重通知和多重 Intent