在GPS和网络上禁用GPS LocationListener调用onProviderDisabled

时间:2016-04-21 08:35:01

标签: android gps locationmanager locationlistener

正如问题所说,当我在设备上禁用GPS时,函数onProviderDisabled(String Provider)会被调用两次(对于gps,然后是网络)。但我仍然获得网络职位onLocationChanged(Location location)

为什么会这样?

当启用GPS时,onProviderEnabled会被调用两次..用于GPS和网络

LocationListener[] mLocationListeners = new LocationListener[] {
            new LocationListener(LocationManager.GPS_PROVIDER),
            new LocationListener(LocationManager.NETWORK_PROVIDER),
            new LocationListener(LocationManager.PASSIVE_PROVIDER)
    };

private class LocationListener implements android.location.LocationListener
{

  @Override
    public void onLocationChanged(Location location)
    {
        globalVariables.DebugLogging("here"+location);
    }

    @Override
    public void onProviderDisabled(String provider)
    {
        if (provider.equals("gps")) {
            GPS_ENABLED = false;
        }
        else
        {
            NETWORK_ENABLED = false;
        }
        globalVariables.DebugLogging( "onProviderDisabled: " + provider);
    }
    @Override
    public void onProviderEnabled(String provider)
    {
        if (provider.equals("gps")) {
            GPS_ENABLED = true;
        }
        else
        {
            NETWORK_ENABLED = true;
        }
        globalVariables.DebugLogging( "onProviderEnabled: " + provider);
    }
}

0 个答案:

没有答案