New Android Geofence Api - Sample code does not alert/notify when at location

Torri Veganas picture Torri Veganas · May 22, 2013 · Viewed 10.9k times · Source

I need some clarity on the sample code supplied with Geofence guide as posted here :

https://developer.android.com/training/location/geofencing.html

I ran the code and I see that geofences are created correctly, but what I really want is a way to get alerted when I drive to those geofenced locations. Right now, when I go past those geofenced spots, nothing happens (ReceiveTransitionsIntentService does not get called), no notifications nothing.

Do I also have to listen to periodic location updates and pass lat/lng to the above piece of code manually to indicate my current location? I thought this should be automatic when I add geofences to LocationClient, but I guess there is more.

I also tried registering a LocationRequest to the LocationClient instance, but still no alerts :

mLocationRequest = LocationRequest.create();
mLocationRequest.setInterval(LocationUtils.UPDATE_INTERVAL_IN_MILLISECONDS);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setFastestInterval(LocationUtils.FAST_INTERVAL_CEILING_IN_MILLISECONDS);

mLocationClient.requestLocationUpdates(mLocationRequest, (LocationListener)mActivity);

How does one integrate Geofence api with location tracking?

Answer

mari picture mari · Aug 8, 2014

I also had issues. Make sure your path is defined correctly when adding the service to your AndroidManifest. I also had to change the exported value to true.

<application>
...
    <service
        android:name=".ReceiveTransitionsIntentService"
        android:exported="true" >
    </service>
...
</application>

You also need to add the meta-data tag in your Manifest to specify your google gms version.

<application>
...
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="4242000" />
...
</application>

I've created a much simpler version of the Google example, with code and more explanation, here. Hope that helps!