Android LED Notification When Screen On

How can I make an LED or trackball pulse or flash while the application is running and the screen is on? For example, when is a phonecall received, for example?

thanks

+4
source share
3 answers

Android has a hard-coded functionality that only turns on when the screen is off. This is in the source of NotificationManagerService.java:

// lock on mNotificationList private void updateLightsLocked(){ ... // Don't flash while we are in a call or screen is on if(mLedNotification == null || mInCall || mScreenOn){ mNotificationLight.turnOff(); }else{ ... } } 

This is a function. Non-attached parts are put ... while the actual behavior for this is in the comment and in the visible code.

We cannot change this. But it's good to know for our debugging and testing LED notifications.

+3
source

I wrote this class a while ago, but I was not able to get it to work (even using different combinations of flags). You may find this post helpful.

 public class NotificationUtils { public static void showStatusbarNotification(Context context, CharSequence text) { NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.icon, text, System.currentTimeMillis()); notification.ledARGB = Color.BLUE; notification.ledOnMS = 100; notification.ledOffMS = 100; notification.defaults |= Notification.DEFAULT_LIGHTS; notification.flags = notification.flags | Notification.DEFAULT_LIGHTS | Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_SHOW_LIGHTS; CharSequence contentTitle = context.getText(R.string.app_name); CharSequence contentText = text; Intent notificationIntent = new Intent(context, MyActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); nm.notify(0, notification); } } 
0
source

I have studied this in the past, and it seems that the Android code is hardcoded to turn off the LED when the screen appears for standard notifications raised by the developers.

I will try to find the code in android again, where I saw it.

0
source

All Articles