请参阅Android 源代码以获取答案:
<!-- 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 可能有不同的值。例如我的回报5000
为config_defaultNotificationLedOff
. 所以你可能想在运行时获取它们:
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+)上。