0

Is there a way to exclude WIFI when requesting coarse location? I don't want to use GPS because of the power consumption and the longer time that it takes to aqcuire the location.

But I need to get the location only from the cell phone towers. The NETWORK_PROVIDER mode also uses WIFI (accesspoint MAC addresses) that google has on its database. I don't want to use those. Is there a way to exclude WIFI from NETWORK_PROVIDER ?

Thanks !

user2566468
  • 179
  • 2
  • 11

1 Answers1

2

One way of obtaining this is to use PASSIVE_PROVIDER, which as stated here:

A special location provider for receiving locations without actually initiating a location fix.

This provider can be used to passively receive location updates when other applications or services request them without actually requesting the locations yourself. This provider will return locations generated by other providers. You can query the getProvider() method to determine the origin of the location update. Requires the permission ACCESS_FINE_LOCATION, although if the GPS is not enabled this provider might only return coarse fixes.

Constant Value: "passive"

One certain way of obtaining what you want is the following:

ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

State mobile = conMan.getNetworkInfo(0).getState();
State wifi = conMan.getNetworkInfo(1).getState();

After that, you distinguish them by:

if (mobile == NetworkInfo.State.CONNECTED || mobile == NetworkInfo.State.CONNECTING) {
    //mobile
} else if (wifi == NetworkInfo.State.CONNECTED || wifi == NetworkInfo.State.CONNECTING) {
    //wifi
}

Check, if the mobile or wifi is connected, if wifi - then use PASSIVE_PROVIDER, if mobile - use NETWORK_PROVIDER.

Cheers :)

g00dy
  • 6,752
  • 2
  • 30
  • 43