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?
Related
I am making an alarm app for waking up user at an exact time.
I am using JobIntentService (since Android O+ devices don't support background services) for showing a notification alarm like this:-
(AlarmManager -> BroadcastReceiver -> JobIntentService -> ShowNotification).
But now on Android O+ devices the JobIntentService gets delayed due to the doze mode and the notification alarm is not shown at the exact time.
Even when i use setExactAndAllowWhileIdle() the AlarmManager gets out of doze mode but JobIntentService still gets delayed.
I can't figure out any alternatives for my case/scenario other than the option below:-
Since the user will have to play a game to stop\snooze the alarm,
a persistent foreground service will keep playing the alarm until user opens the app(by tapping the foreground service). The alarm will be kept playing until the user plays the game. The foreground service (on-going alarm) will stop once the user is done playing the game.
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.
I am working on ibeacon and it is working perfectly fine when app is in foreground or when device is awake but app is in background. The issue is when device goes to sleep mode. iBeacon default methods gets stopped and start working as soon as device awakes. It does not matter whether app is in foreground or background.
I tried wake lock and alarm manager. But failed. Please suggest
I have an android application that uses Geofence and I'm having a hard time overcoming Doze mode. My manifest has the WAKE_LOCK permission and seven setNotificationResponsiveness to 0 for each region. I even changed PendingIntent to BroadcastReceiver but the app literally sleeps or is dead after a while with the deleted smartphone screen. I've already tried using LocationRequest
LocationRequest.setFastestInterval(1000);
LocationRequest.setInterval(2000);
Even so, I did not succeed. Has anyone managed to keep the application running with the Doze?
I faced the issues in My Chatting application and Location Tracking applications, While in doze mode we will not get any push, or we will not get any network connection or location details and most of the background operation will be blocked because of battery optimization, We can solve by 2 ways.
Priority push message(I used in my chatting application) - If you send normal push it will not reach the app until the mobile come to normal, If you send priority push it will reach the app you can do some process within few seconds, but this also have some limitation.
Foreground service, - For your scenario this is the best solution, You should have on service and that service should run as Foreground service so that you can get the Location information all time even in Doze mode.
WAKE_LOCK permission in the manifest is not enough for use a Wake Lock , you need to acquire and release the lock in your code, but starting with Android 6 Doze mode it goes to deep sleep also with an acquired wake_lock.
The way that works for me also with Doze mode :
In the Main Activity onStop I acquire a Partial WakeLock and I start a Service with STARTFOREGROUND_ACTION intent, the Service calls startForeground and shows a Notification.
On Activity onResume the WakeLock is released, the Service stops with STOPFOREGROUND_ACTION intent and the Service itself calls stopForeground & stopSelf.
I ended up putting my application to receive push messages. Apparently the app is no longer being killed by the operating system.
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.