Doze mode sleeps Google's Geofence sample application
Asked Answered
C

3

1

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?

Cowlick answered 12/6, 2017 at 17:26 Comment(0)
C
0

I ended up putting my application to receive push messages. Apparently the app is no longer being killed by the operating system.

Cowlick answered 20/6, 2017 at 16:41 Comment(0)
S
0

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.

  1. 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.

  2. 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.

Scherzando answered 12/6, 2017 at 17:46 Comment(3)
the item 2 you have a sample(Foreground service)? I've been researching the subject and trying to build this solution. But my scenario does not know if I'm doing it wrong or does not fit the design. I have a gps class that takes the location of the device in this location when the geofence event occurs, it makes a call to the server to determine which geofence area has been activated and the location of the device.Cowlick
How can I apply this service to update the Location? This forground service I saw posts saying that I should create a notification and then I did not understand why. Strange to Google not update the official part of Geofence by remedying this problem with the Doze.Cowlick
Currently the app has an AlarmManager that from time to time generates a log that I can see if the app has not been closed or is sleeping but, the Geofence system seems to sleepCowlick
B
0

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.

Brussels answered 12/6, 2017 at 17:52 Comment(3)
I got this error log WakeLock finalized while still held:MyBroadcastReceiver. This error occour when app still background and device screen off. MyBroadcastReceiver extends now WakefulBroadcastReceiver.Cowlick
Try without any wake_lock, the Service + startForeground should be enough.Brussels
doesn't work, app sleep/ dead when device screen is off.Cowlick
C
0

I ended up putting my application to receive push messages. Apparently the app is no longer being killed by the operating system.

Cowlick answered 20/6, 2017 at 16:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.