Testing geofencing with Google Play Services 6.5.+

Redwarp picture Redwarp · Mar 13, 2015 · Viewed 10.4k times · Source

I've been testing the geofencing api available in the latest Google Play Services, using the official sample available here: https://github.com/googlesamples/android-Geofencing/ And of course, following the training course: http://developer.android.com/training/location/geofencing.html

The sample displays a notification when you are nearing two Google buildings in San Fransisco, so I tweaked it to be triggered when I'm nearing my home or my work place.

If I use a real device, it works. The notifications are triggered properly. But when I'm using a simulator, and change the location with telnet or ddms, nothing happens. I also tried with Genymotion, with the Gapps installed, and same stuff: nothing.

Would anyone have any pointer about how to test geofence, without actually moving my butt? Because in the street, there is no way to debug the code...

Answer

Snake picture Snake · Apr 2, 2015

Here is what you need to do:

  1. Settings -> Developer options -> Allow mock locations

  2. Add the following permission:

<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />

  1. Ensure your GPS location service is ON (high accuracy) not Network location

  2. Download an app called Fake GPS (it has yellow happy fact holding a remote control) from the app store. You can set your fake GPS using that app

Hope this answers you question :)