Added Location Provider Changed Receiver to Reregister the geofences

merge-requests/236/head
Zohaib Kambrani 5 years ago
parent 187d2bcd8b
commit 3392a2431b

@ -81,7 +81,11 @@
<receiver android:name=".geofence.intent_receivers.GeofencingRebootBroadcastReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<!-- <action android:name="android.intent.action.BOOT_COMPLETE"/>-->
</intent-filter>
</receiver>
<receiver android:name=".geofence.intent_receivers.LocationProviderChangeReceiver">
<intent-filter>
<action android:name="android.location.PROVIDERS_CHANGED"/>
</intent-filter>
</receiver>

@ -0,0 +1,32 @@
package com.cloud.diplomaticquarterapp.geofence.intent_receivers
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.location.LocationManager
import android.util.Log
import com.cloud.diplomaticquarterapp.geofence.GeofenceTransition
import com.cloud.diplomaticquarterapp.geofence.HMG_Geofence
import com.cloud.diplomaticquarterapp.geofence.PREFS_STORAGE
import com.cloud.diplomaticquarterapp.utils.HMGUtils
import com.cloud.diplomaticquarterapp.utils.saveLog
import com.google.android.gms.location.GeofencingEvent
class LocationProviderChangeReceiver : BroadcastReceiver() {
private val LOG_TAG = "LocationProviderChangeReceiver"
override fun onReceive(context: Context, intent: Intent) {
if (LocationManager.PROVIDERS_CHANGED_ACTION.equals(intent.action)) {
val pref = context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
pref.edit().putString("LOCATION_PROVIDER_CHANGE","YES").apply()
HMG_Geofence.shared(context).unRegisterAll { status, exception ->
val geoZones = HMGUtils.getGeoZonesFromPreference(context)
HMG_Geofence.shared(context).register(geoZones)
}
}
}
}
Loading…
Cancel
Save