如何检查Android设备是否支持GPS或不? [英] How to check whether an android device has gps support or not?
问题描述
我试图写一个检查GPS支持Android设备的方法。
虽然有GPS模拟器上的支持,它总是返回false。但是当我尝试在我的Android设备则返回true。可能是什么原因呢?
公共布尔isGpsAvailable(){
软件包管理系统下午= this.getPackageManager();
如果(pm.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS)){
返回true;
}其他{
返回false;
}
}
如果您使用的是的LocationManager,您可以使用此方法:
<一个href=\"http://developer.android.com/reference/android/location/LocationManager.html#getAllProviders%28%29\" rel=\"nofollow\">http://developer.android.com/reference/android/location/LocationManager.html#getAllProviders%28%29
再通过所有的字符串看起来回来,查看是否有一个GPS提供商。
i'm trying to write a method which checks the gps support of android device. Although having gps support on emulator, it always returns false. But when i try it on my android devices it returns true. What can be reason of that?
public boolean isGpsAvailable() {
PackageManager pm = this.getPackageManager();
if (pm.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS)) {
return true;
} else {
return false;
}
}
If you're using a LocationManager, you could use this method:
http://developer.android.com/reference/android/location/LocationManager.html#getAllProviders%28%29
Then look through all of the strings returned, and see if one is a GPS provider.
这篇关于如何检查Android设备是否支持GPS或不?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!