During development of an Android app, I would like to use the notification LED for an unobtrusive way of debugging, eg. when something happens, it should switch to red.
I already realized that it is not that easy to use, since I have to use a notification.
This is my code to let it flash in red:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void buttonClicked(View theButton) {
switch (theButton.getId()) {
case R.id.buttonRedlight:
notificationRedlight();
break;
}
}
private void notificationRedlight() {
Notification notification = new Notification.Builder(this).
setContentTitle("I love rock and roll")
.setContentText("So put another dime in the jukebox baby")
.setSmallIcon(R.drawable.notificationimage)
.build();
notification.ledARGB = 0xffff0000;
notification.ledOnMS = 2000;
notification.ledOffMS = 500;
notification.flags = Notification.FLAG_SHOW_LIGHTS;
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(5, notification);
}
}
Unfortunately, this only lets the led flash when the screen is off. When I switch it on again, the led goes dark again.
Is there any way to extend the notification leds to "normal operation"?
Android API: 23
User contributions licensed under CC BY-SA 3.0