我想创建一个自定义通知。所以我想改变灯光和音调。
为此,我使用了 NotificationCompat.Builder
。
现在我想通过 setLights()
改变灯光;
工作正常。但我想设置 onMS
和 offMS
的默认值。我还没有找到相关信息。
谁能帮我找到默认值? 这是相关文档: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/