如何检查Android设备是否支持GPS或不? [英] How to check whether an android device has gps support or not?

查看:548
本文介绍了如何检查Android设备是否支持GPS或不?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写一个检查GPS支持Android设备的方法。
虽然有GPS模拟器上的支持,它总是返回false。但是当我尝试在我的Andr​​oid设备则返回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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆