android / location-samples

Multiple samples showing the best practices in location APIs on Android.
Apache License 2.0
2.71k stars 2.78k forks source link

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

Open Fraid opened 4 years ago

Fraid commented 4 years ago

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.

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

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?)

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

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

  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!

murat0 commented 4 years ago

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

Fraid commented 4 years ago

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.

MrFuFuFu commented 4 years ago

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.

Fraid commented 4 years ago

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.

DomClaxton commented 3 years ago

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.

filipebezerra commented 3 years ago

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.

GonzRon commented 2 years ago

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