Awake phone from sleep with chronometer timer - android

I am making an interval timer for a stopwatch APP, and I'm using chronometer to display notifications (Run, walk, stop) and play sound. But when the phone is in sleepmode it doesn't do anything.
Is there a way to wake up the phone, to show these notifications (and play the sound), or must I use AlarmManager?
I know how to make the phone stay awake with wakelock and FLAG_KEEP_SCREEN_ON, but I don't know how to awake it from sleep.

Use AlarmManager. There is nothing else timer-based that will wake up the device out of sleep mode.

Related

Vibrate in BroadcastReceiver in Android Q

I have created an alarm app years ago, it vibrates in background (while app is closed), using Alarm and BroadcastReceiver.
But now in Android Q (v10), I can't start vibrate from background and I should run a foreground service. The new problem is if device is locked and screen is off, sometimes system decides to hold/freeze the foreground service until screen is turned on by user, then it will vibrate, maybe minutes after real alarm time!
Is there any trick to vibrate without running a foreground service?

Does a foreground service need a wake lockt to stay active after screen-off?

In different sources, I read that a foreground service requires a wake lock to stay active after the device goes to sleep. But when I test it by starting a foreground service and turning the screen off while the device is unplugged (both on emulator and on a real Samsung device), the foreground service keeps running.
Does a foreground service require a (partial) wake lock to stay active after the screen is off?
From my experience of developing a timer, the answer is yes, especially when the screen is off.
Without a wake lock, the foreground service will be killed or suspended in a few minutes(2 ~ 10m in my tests). Sometimes, when the screen is off, the code won't be executed but the foreground notification still exists and the code only starts being executed after the screen is turned on. This makes debug very hard. This situation is more common if the test device is from Chinese manufacturers(Foreground service + Wake Lock + Letting user whitelist your app seems the only solid option if your app targets Chinese market).
Use a wake lock if you want your service keep running after the screen is off.

Android: Does CountDownTimer still work after the phone gone to sleep

Will the CountDownTimer work when the phone gone to sleep mode? If it doesn't, is there a broadcast receiver which I can detect whether the phone gone to sleep and awake again?

wakes up my device from standy mode at a particular time

I m new to android world n m trying to make an app that wakes up my device from standy mode at a particular time.
I tried a few places where they mentioned about wakelock but this thing just prevents the device from going into standy mode.
I basically want my device to wake up from standby mode.
Like take the example of alarm clock... once set i can leave it and at that time from standby mode I get to see that the phone is active.
I even tried developer site for android... but it wasn't much helpful!
Any help would be highly appreciated!
You have to use Alarm Manager to schedule a repeated alarm (use RTC_WAKEUP for type parameter).
Then your code will execute even if the device is sleep. but notice that the registered alarm will removed once the device is restarted so you have a re-schedule the alarm again (by listening to boot broadcast)

Android AlarmManager RTC doesn't pause while device is sleeping

I wrote a little widget for Android devices.
The widget uses AlarmManager to set recurring updates.
I'm using the RTC clock for the AlarmManager.
According to the documentation, if the device is sleeping, the RTC clock won't wake up the device and the next update will be when the device is woken.
I have a log file for the widget which shows when it was updated.
Even when I don't touch the device , I still see updates in the log file.
Why is that? shouldn't the device be sleeping and thus my widget shouldn't update?
I'm using System.currentTimeMillis() for the starting time so it should be correct for RTC clock.
You need to disconnect device from your desktop. When device is charging it doesn't go to sleep mode even when screen is black.

Categories

Resources