android / location-samples

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

Geofencing sample: "Geofence service is not available now" #161

Open RikdeBoer opened 6 years ago

RikdeBoer commented 6 years ago

Using API 26 / 27

App compiles and starts fine. App pops up in emulator (set to Oreo/ Android 8 device), showing two buttons "Add Geofences" and "Remove Geofences" (greyed-out).

Press "Add Geofences".

Seeing this in the log: com.google.android.gms.location.sample.geofencing W/MainActivity: Geofence service is not available now

Any special Settings that I'm not aware of?

RikdeBoer commented 6 years ago

Yes. Didn't realise I had to do this (at least in emulator for Oreo)

Settings -> Security & Location -> Location -> App-level Permissions -> Creating and Monitoring Geofences ON

RikdeBoer commented 6 years ago

After making the above setting, I cannot get this app to do anything noticeable, at least on Oreo 8 emulator.

There's a button "Add Geofences". When I look in the debugger I can see it adds 2 locations, SFO and GOOGLE with a 1 mile geofence radius around them.

Using the 3-dots command (...) on the emulator I have set lat/lon to be close then far away from SFO and GOOGLE. No function seems to get triggered.

Some instructions on how to use this sample app and what it is intended to do would be most welcome...

ergun-p commented 5 years ago

+1

rohitsharma181589 commented 5 years ago

I am facing this issue on testing device 'LG Q6' Android version 7.1.1 I am using the sample app for geofencing and when i click on Add Geofence button it throws an error "Geofence service is not available now" ,please suggest on this.

nandovelazquez commented 5 years ago

I faced the same problem and I fix it restarting the device. I'm using a Pixel with android 9.

Also you can use an app called Lockito to fake a gps route so the Geofacing app can determine if it enters/exit of the geofence zone.

olddustysocksunderthecouch commented 5 years ago

On API 25 I had to go into Settings --> Location --> Mode --> select either Battery saving or High Accuracy. Geofences use wifi and cellular networks to determine your location so if you leave it in device mode which only has access to GPS, geofences won't work.