问题
I'm trying to turn the LED-flashing on for my activity in foreground, but it works only when the screen is off.
Is it possible to turn the LED on for active activity with the screen on?
My code:
protected void led() {
Notification notif = new Notification();
notif.ledARGB = 0xFF0000ff;
notif.flags = Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_ONGOING_EVENT;
notif.ledOnMS = 800;
notif.ledOffMS = 200;
notificationManager.notify( LED_NOTIFICATION_ID, notif );
}
回答1:
At first Android LED indicator is very hardware dependent. Second - there is no API for managing LED instead of Notification
class with its FLAG_SHOW_LIGHTS
flag and several flags for managing flash duration and LED color which you use. Notification
is a message you can display to the user outside of your application's normal UI the primary purpose of LED indicator is to present additional notification information for the user when the screen is off. So the answer is definite NO. The LED will only start flashing if your screen is off and it’ll stop when you turn it back on. And there is no way to turn on and off LED when you want and to turn it when any of the application activities is in foreground, because it is managed by the OS internally.
来源:https://stackoverflow.com/questions/17810814/showing-flashing-led-for-foreground-activity-screen-on