B
B
Bogdan2019-03-20 19:42:25
Android
Bogdan, 2019-03-20 19:42:25

LocationManager (Geolocation) trigger?

Hello. Tell me please. In Android 6+, to get a list of Wifi networks, you need to enable geolocation. The inclusion of geolocation occurs through the launch

if (!locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
            Intent settingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivity(settingsIntent);
   }

The settings window with the switch is launched, but now how to catch the change?
Tried via BroadcastReceiver but doesn't work.
protected void onCreate(Bundle savedInstanceState) {
        ...
        registerReceiver(gpsReceiver, new IntentFilter(LocationManager.PROVIDERS_CHANGED_ACTION));
      ...
}

    private BroadcastReceiver gpsReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().matches(LocationManager.PROVIDERS_CHANGED_ACTION)) {
                //Do your stuff on GPS status change
                Log.i("TEST_WIFI", "CHANGE LOCATION");
            }
        }
    };

Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
z0rgoyok, 2019-03-20
@z0rgoyok

in onResume check, well, or by timer

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question