I have minor issue here.
I have taken all the necessary location permissions from the user.
I have created Broadcast Receiver as below :
public class GpsLocationReceiver : BroadcastReceiver() {
private lateinit var mLocationManager: LocationManager
override fun onReceive(context: Context, intent: Intent) {
LogUtil.e(">>>On Receive","called")
mLocationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
LogUtil.e(">>>On Receive","called inside")
GetLocationAccessFragment().getAndSaveCurrentLocation()
}
}
}
In my manifest i have done as below :
<receiver android:name=".ui.user_profile.fragments.GetLocationAccessFragment$GpsLocationReceiver">
<intent-filter>
<action android:name="android.location.PROVIDERS_CHANGED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
Now, for am registering it in my fragment init() method :
mContext.registerReceiver(
GpsLocationReceiver(),
IntentFilter(LocationManager.PROVIDERS_CHANGED_ACTION)
and, unregistered it when work finished :
mContext.unregisterReceiver(GpsLocationReceiver())
But, Unfortunately, OnReceive() method is not getting called when I TurnOn/TurnOff GPS in my device. What might be the issue ?