I am trying to turn on an LED notification, such as green. Turn off the screen, and every 5 seconds, change the color to red (green - red, red - green). I think I did everything: in the service, I created a timer that executes a method to display a notification.
public class LEDService extends Service { private boolean TimerStarted; private Timer timer; private NotificationManager myNotificationManager; private long LastColor; public TurnLedOn() { Notification notify = new Notification(); notify.flags |= Notification.FLAG_SHOW_LIGHTS; notify.LedOnMS = 500; notify.LedOffMS = 0;
What is the problem? The LED does not change color ... When I turn off the screen, the color turns green until I turn on the screen and turn it off again. I want to start this service once, turn off the screen and see the color of the LED backlight :).
By the way: I checked my phone and it MAY show green and red lights so that it is not a problem.
Thanks in advance and sorry for my English.
I cannot answer my question, so add this here:
Thanks for your Olsavage suggestions, I added clearAll () to my code, but the effect is the same; /. I also added an entry to my application (Log.i ()). It seems that the system stops my service when the screen turns off (why?) . This is true:
The screen is on: The timer is running and the notification is maximized (but I canβt see that it is on, because to see it I have to turn off the screen: P)
Press the lock button: The timer is almost stopped, so the LED sometimes changes color once.
Screen off: The timer does not work, the TurnLedOn method no longer works. LED does not change color.
Now the question is: why is my service stopped after turning off the screen ? Even when I perform a simple operation in it (for example, increasing a variable). Maybe I need to set priority or something else?
I changed the timer interval to 100 ms and realized that the code is good. The LED changed colors for 5-15 times, but then stopped immediately. I know this application is completely useless, but I just want it to work :).
EDIT2: I think I will have to use AlarmManager and PendingIntent to start my service ... Tomorrow I will try to do it.