Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notification setLights() Default Value?

I want to create a custom notification. So i want to change the lights and the tone. I use the NotificationCompat.Builder for that.

Now i want to change the Lights via setLights(); Works fine. But i want set the default value of the onMS and offMS. I haven't find something about that.

Can anybody help me to find the default values? Here is the documentation for that: http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setLights(int, int, int)

like image 888
StefMa Avatar asked Feb 27 '13 10:02

StefMa


People also ask

What is Channel ID in Android notification?

ChannelId is a unique String to identify each NotificationChannel and is used in Notification.

How do I make my notification icons smaller?

Set the small icon resource, which will be used to represent the notification in the status bar. Set the small icon, which will be used to represent the notification in the status bar and content view (unless overridden there by a large icon ).

How do you add notification in Android app explain with an example?

To associate the PendingIntent with a gesture, call the appropriate method of NotificationCompat. Builder. For example, if you want to start Activity when the user clicks the notification text in the notification drawer, you add the PendingIntent by calling setContentIntent().


1 Answers

See the Android source for answer:

<!-- 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>

However different ROMs might have different values for these. For example mine returns 5000 for config_defaultNotificationLedOff. So you might want to fetch them at runtime:

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")));

According to diff, these attributes are guaranteed to exist on Android 2.2+ (API level 8+).

like image 197
Mygod Avatar answered Sep 18 '22 00:09

Mygod