1

I spent hours but could not find an exact way to re - register geofences through a BroadcastReceiver. Re-registering requires the GoogleApiClient instance to be running in an activity and hence the app. Please help. Please tell me if wrong or provide a solution.

Do Geofences remain active in android after a device reboot.

Community
  • 1
  • 1
Ashish
  • 21
  • 6

1 Answers1

0

First you need to have a GeofenceManager to handle all the persistence Geofence regions storage, you can persists your geofence region by saving each attribute on a preference key. After that you can implement a BroadcastReceiver to restore all your geofence regions from preferences.

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class GeofenceBootReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {

    GeofenceRegionsManager manager = new GeofenceRegionsManager(context);
    manager.restoreAllRegions();
  }
}

Should set permission:

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

And set intent filter action android.intent.action.BOOT_COMPLETED on AndroidManifest.xml.

Rendy Del Rosario
  • 1,277
  • 10
  • 20
  • Thanks for replying. I solved my problem though. Am starting a service in onReceive() and the service is taking take of the GoogleApiClient. – Ashish Oct 25 '15 at 15:00
  • Please mention that "GeofenceRegionsManager" is a custom class. I ended up looking for documention on using GeofenceRegionsManager class, as it's not clear in your answer. Thanks! – Ashish Oct 25 '15 at 15:03