【问题标题】:How to check whether an android device has gps support or not?如何检查android设备是否支持gps?
【发布时间】:2012-01-02 23:53:41
【问题描述】:

我正在尝试编写一种方法来检查 android 设备的 gps 支持。 尽管在模拟器上有 gps 支持,但它总是返回 false。但是当我在我的 android 设备上尝试它时,它返回 true。这可能是什么原因?

public boolean isGpsAvailable() {
    PackageManager pm = this.getPackageManager();
    if (pm.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS)) {
        return true;
    } else {
        return false;
    }
}

【问题讨论】:

  • 顺便说一句,它不仅仅在模拟器上工作。它在我的安卓设备上完美运行。
  • 请注意,您的代码将在FROYO之前在设备上崩溃。 PackageManager.FEATURE_LOCATION_GPS 是 API LEVEL 8

标签: android gps


【解决方案1】:

如果你使用的是 LocationManager,你可以使用这个方法:

http://developer.android.com/reference/android/location/LocationManager.html#getAllProviders%28%29

然后查看所有返回的字符串,看看是否有一个 GPS 提供商。

【讨论】:

  • 我以前试过你的方法,效果很好。但我真的很想知道为什么这段代码 sn-p 不起作用?
猜你喜欢
  • 1970-01-01
  • 2023-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-25
  • 1970-01-01
  • 2018-09-03
相关资源
最近更新 更多