문제

If I am using the LocationManager.NETWORK_PROVIDER is there a way to know if the location that triggered onLocationChanged came from a WiFi connection or from a cell tower connection?

도움이 되었습니까?

해결책 2

Update: The below answer will only provide either GPS or Network as the provider. Here is a similar question that may be helpful. How to know the positioning mode is WIFI or 2G/3G cell tower in Android?

Are you using onLocationChanged method inside the LocationListener to get the coordinates? If so you can use the location.getProvider() method to get the provider.

LocationListner locationListner = new LocationListener(){
    public void onLocationChanged(Location location){
        String provider = location.getProvider(); 
    }
}

다른 팁

You can ask with

public void onLocationChanged(Location location){
    String provider = location.getProvider(); 
}

or

    ConnectivityManager connectivityManager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
    //android.net.NetworkInfo
    NetworkInfo wifi = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    NetworkInfo mobile = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);


        if(wifi.isAvailable() && wifi.getDetailedState() == DetailedState.CONNECTED)
            locationProvider = LocationManager.NETWORK_PROVIDER;
        else //check if it is a tablet without 3G connection
            if(mobile!=null){
                if(mobile.isAvailable() && mobile.getDetailedState() == DetailedState.CONNECTED)
                     locationProvider = LocationManager.PASSIVE_PROVIDER;
            }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top