简体   繁体   English

如何检查 android 设备是否支持 gps?

[英]How to check whether an android device has gps support or not?

i'm trying to write a method which checks the gps support of android device.我正在尝试编写一种方法来检查 android 设备的 gps 支持。 Although having gps support on emulator, it always returns false.尽管在模拟器上支持 gps,但它总是返回 false。 But when i try it on my android devices it returns true.但是当我在我的 android 设备上尝试它时,它返回 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:如果您使用的是 LocationManager,则可以使用此方法:

http://developer.android.com/reference/android/location/LocationManager.html#getAllProviders%28%29 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.然后查看所有返回的字符串,看看是否有一个是 GPS 提供程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM