简体   繁体   English

如何查看手机是否有 GPS 设备?

[英]How can I check whether the phone has GPS device or not?

I am trying to find piece of code which can tell me whether the android phone has GPS device or not?我试图找到一段代码,它可以告诉我 android 手机是否有 GPS 设备? Most of the samples I am getting in search results are telling whether GPS is enabled or not.我在搜索结果中获得的大多数样本都在说明 GPS 是否已启用。 What I am interested in is whether Android phone has Physical GPS device or not?我感兴趣的是 Android 手机是否有物理 GPS 设备?

Thanks谢谢

Starting with API level 8 (Froyo), you can use the following code:从 API 级别 8 (Froyo) 开始,您可以使用以下代码:

PackageManager packageManager = mContext.getPackageManager();
boolean hasGPS = packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
public boolean hasGPSDevice(Context context)
    {
    final LocationManager mgr = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
    if ( mgr == null ) return false;
    final List<String> providers = mgr.getAllProviders();
    if ( providers == null ) return false;
    return providers.contains(LocationManager.GPS_PROVIDER);
    }

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

相关问题 如何检查 android 设备是否支持 gps? - How to check whether an android device has gps support or not? Android:如何检查GPS是否在我的Android设备上工作? - Android :How can i check whether GPS is working in my android device or not? 如何检查Android设备GPS模块是否具有A-GPS支持 - How to check whether Android device GPS module has A-GPS support 如何检查设备是否具有GSM或GPS功能? - How to check if device has GSM or GPS ability? GPS服务检查,以检查是否在设备上启用或禁用了GPS - GPS Service Check, to check whether GPS is enabled or disabled on a device 如何检查Android设备是否连接到网络? - How can i check whether an android device is connected to the web? 如何检查 SIM 卡是否可用于 Android 设备? - How can I check whether the Sim Card is available in an android device? 我向用户显示了启用gps设置的提示,但是如何检查用户是否在手机上真正启用了gps位置? - i showed prompt to user to enable gps settings,but how can i check user really enabled the gps location on his phone? 如何检查该列是否已值? - How can I check whether the column already has value? 使用Unity Engine如何判断设备是手机还是平板,C#可以做到吗? - How can I determine whether the device is a phone or tablet using the Unity Engine, and can it be done in C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM