Notification setLights () Default?

I want to create a custom notification. So I want to change the light and tone. For this I use NotificationCompat.Builder .

Now I want to change the light through setLights() ; Works great. But I want to set the default onMS and offMS . I did not find anything about this.

Can someone help me find the defaults? Here is the documentation for this: http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setLights (int, int, int)

+8
android notifications android-notifications
source share
3 answers

See Android source for an 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, for different ROMs there may be different values. For example, my returns 5000 for config_defaultNotificationLedOff . Therefore, you might want to get 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 +).

+6
source share

You can do this with:

 Notifictaion notf = new Notification.Builder(this).setXXX(...).....build(); notf.ledARGB = <your color>; notf.ledOnMS = <your value>; //or skip this line to use default notf.ledOffMS = <your value>; //or skip this line to use default 

Basically, do not use setLights in the notification builder. Instead, first create a notification - then you have access to individual fields for highlighting.

Update: this is the actual copy / paste from my sample project, which compiles and works fine on Android 2.1 and uses blue for LEDs:

 Notification notf = new NotificationCompat.Builder(this) .setAutoCancel(true) .setTicker("This is the sample notification") .setSmallIcon(R.drawable.my_icon) .build(); notf.ledARGB = 0xff0000ff; NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(1, notf); 
+1
source share

@Aleks G which do not help. I have the latest update from share libaray. But Eclipse says build() not available. I do not know why. The document says yes, and you ...

This is my current code:

  NotificationCompat.Builder notify = new NotificationCompat.Builder(context); notify.setLights(Color.parseColor(led), 5000, 5000); notify.setAutoCancel(true); notify.setSound(Uri.parse(tone)); notify.setSmallIcon(R.drawable.ic_stat_kw); notify.setContentTitle("Ttiel"); notify.setContentText("Text"); Intent showIntent = new Intent(context, Activity_Login.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, showIntent, 0); notify.setContentIntent(contentIntent); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notify.getNotification()); 

works great. But not by default onMS and offMS in setLights() : (

+1
source share

All Articles