My Geofence works at the start, but then suddenly after starting a day or two stops, is there a problem on the Google side here or on my code?
When loading and starting the application, I use IntentService, which then logs Geofence:
public class RegisterGeoIntentService extends IntentService implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, ResultCallback<Status> { private static final String TAG = "RegisterGeoIS"; private static final long TIME_OUT = 100; protected GoogleApiClient mGoogleApiClient; protected ArrayList<Geofence> mGeofenceList; private PendingIntent mGeofencePendingIntent; public RegisterGeoIntentService() { super(TAG); } @Override public void onCreate() { super.onCreate(); Log.i(TAG, "Creating Register Geo Intent service"); mGeofenceList = new ArrayList<Geofence>(); mGeofencePendingIntent = null; } @Override protected void onHandleIntent(Intent intent) { buildGoogleApiClient(); populateGeofenceList(); mGoogleApiClient.blockingConnect(TIME_OUT, TimeUnit.MILLISECONDS); String connected = mGoogleApiClient.isConnected() ? "connected" : "disconnected"; Log.i(TAG, "Restoring geofence - status: " + connected); String mode = null; if(intent != null) { mode = intent.getStringExtra(GEOFENCE_MODE); if(mode.equals(GEOFENCE_MODE_START)) { removeGeofencesButtonHandler(); addGeofencesButtonHandler(); } else { removeGeofencesButtonHandler(); } } else { Log.e(TAG, "No Intent data, could not start Geo"); } } @Override public void onConnected(Bundle bundle) { Log.i(TAG, "Connected to GoogleApiClient"); } @Override public void onConnectionSuspended(int i) { Log.i(TAG, "Connection suspended"); } @Override public void onConnectionFailed(ConnectionResult result) { Log.i(TAG, "Connection failed: ConnectionResult.getErrorCode() = " + result.getErrorCode()); } @Override public void onResult(Status status) {
And this:
public class GeofenceReceiver extends BroadcastReceiver { ... @Override public void onReceive(Context context, Intent intent) { this.context = context; GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); if(geofencingEvent.hasError()) { String errorMessage = GeoErrorMessages.getErrorString(context, geofencingEvent.getErrorCode()); Log.e(TAG, errorMessage); return; } int geofenceTransition = geofencingEvent.getGeofenceTransition(); if(geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {
Also see my answer that I tried and thought I fixed it. But it did not help.
source share