如果我使用LocationManager.NETWORK_PROVIDER
,是否有办法知道触发onLocationChanged
的位置是来自WiFi连接还是来自手机信号塔连接?
答案 0 :(得分:2)
你可以问
public void onLocationChanged(Location location){
String provider = location.getProvider();
}
或
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;
}
答案 1 :(得分:1)
更新:以下答案仅提供GPS或网络作为提供商。这是一个类似的问题,可能会有所帮助。 How to know the positioning mode is WIFI or 2G/3G cell tower in Android?
您是否在LocationListener中使用onLocationChanged方法来获取坐标?如果是这样,您可以使用location.getProvider()方法获取提供程序。
LocationListner locationListner = new LocationListener(){
public void onLocationChanged(Location location){
String provider = location.getProvider();
}
}