location-samples icon indicating copy to clipboard operation
location-samples copied to clipboard

Geofence with Android SDK 29 and DOZE/idle mode (issue summary)

Open Fraid opened this issue 4 years ago • 7 comments

Hi Everyone,

Big/huge thread coming! I got some issue implementing the Geofence API in "idle/doze" mode only. This issue may sound like a duplicate, but most of the answer don't take in consideration the doze mode or don't have an answer. I may worry for nothing but all those open issues doesn't help.

  • Here what I expect as a user:

Notification: "Hey! Bob you're near a printer service, it's time to get your business card done!" When: Well... when the user is near the printer service ^^.

  • Here what I think may happen:

Notification:"Hey!......etc" When 1 : Never When 2 : When ever users use the device and are near that printer services. When 3 : User is near the printer service...(lucky?)

  • The issue I found so far that may be linked:

#200 JobScheduler work well for location update, not geofence (see previous case). #197 what about when your device is idle mode? #204: I don't own a pixel 4, but api should work on most devices #203 Good point! #190 I tested when the app is in background, using the home button. Etc....etc also... #201 #171 #168 #124 asked in 2018

  • What did i personally try:

Read Create and monitor geofences, please help if I miss something. Specially this part Alerts can be late. The geofence service doesn't continuously query for location, so expect some latency when receiving alerts. Usually the latency is less than 2 minutes, even less when the device has been moving. If Background Location Limits are in effect, the latency is about 2-3 minutes on average. If the device has been stationary for a significant period of time, the latency may increase (up to 6 minutes)., because still no notification after 24h.

From this repo I changed the SDK target to 29, changed the location in BAY_AREA_LANDMARKS, created a mock route location loop using the emulator with Android 10 and real device with Android 7.1.1 I put the both devices into idle see documentation. Removed the sample app from optimized battery option and finally having location permission set to "allow all the time". Not a single notification appears (when idle on) .

  • So, that is say the real question now:
  1. Is anyone able to make my case work ?
  2. If so, can you share a working exemple? Their are really to many exemple/advise/guessing that work in some case, for some user...with some weird tweaky hack that could violate google police (Yes! I saw someone talking about translucent notification ).

Finally, I'm talking about Geofence which is not the same thing as Location. For this I'll understand the use of JobScheduler. But! I try to use the sharing feature of google maps without success. I can see a notification "Updating your shared location" every minute, but the online map isn't updated when idle is turned on, Maybe this is the issue here ?

PS: I can help or test/debug , i just don't have a real android 10 device.

Cheers!

Fraid avatar Feb 06 '20 15:02 Fraid

Hi, I am experiencing the exact same issue, what set of permissions have you listed on your manifest file? @Fraid

murat0 avatar Apr 27 '20 15:04 murat0

Hi @murat0 ,

When I tested with Geofencing :

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

But, in our business app I used:

  <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
  <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> 
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 
  <uses-permission android:name="android.permission.WAKE_LOCK" />

Don't think it's linked but additionally:

  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 

I still don't have a solution, yet. Anyone with a hint is welcome! Also google make another change about permission Requesting access to background location, probably we will get more info or we may get like a "special" access for reviewed/approved app.

Fraid avatar Apr 27 '20 17:04 Fraid

Did you manage to make it work? I don't know how those commercial SDKs work, they seem fine, like this: https://pathsense.com/ or others like: Radar, Foursquare, Factual. I guess that's why they're making money from that.

MrFuFuFu avatar May 21 '20 21:05 MrFuFuFu

Sorry, but i'll like to focus on a native solution. I'm working for a company, we provide both IOS and Android apps. It's working on ios natively, i can't request the use of commercial third party.

For other app, our device just die, i'm waiting for the repair. When it's done i'll test Foursquare. Maybe someone could do the test, for reminder the goal is to get a notification while walking near a point of interest while the phone is idle.

Fraid avatar May 26 '20 14:05 Fraid

Anything further happening with this. I'm having similar issues although I have set background task permissions I'm still not able to get the broadcastreceiver to trigger. I created an IOS version and got it working within an hour. This Android version has so far taken me about 7 hours and still no joy.

DomClaxton avatar Nov 29 '20 11:11 DomClaxton

Do you guys tryied to add <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> to AndroidManifest.xml and request that permission in runtime?

In fact ACCESS_BACKGROUND_LOCATION is a required permission when targeting Android O.

filipebezerra avatar Mar 07 '21 17:03 filipebezerra

Read my comment here: https://github.com/android/location-samples/issues/247#issuecomment-950372964

GonzRon avatar Oct 24 '21 18:10 GonzRon