如何检查手机是否有GPS设备或没有? [英] How can I check whether the phone has GPS device or not?

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

问题描述

我想找到一张code,可以告诉我的Andr​​oid手机是否有GPS设备或没有?大多数我得到的搜索结果中的样品告诉GPS是否启用。我所感兴趣的是Android手机是否有物理GPS设备或不?

感谢

解决方案

 公共布尔hasGPSDevice(上下文的背景下)
    {
    最后LocationManager经理=(LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
    如果(经理== NULL)返回false;
    最后的名单,其中,字符串>提供商= mgr.getAllProviders();
    如果(商== NULL)返回false;
    返回providers.contains(LocationManager.GPS_PROVIDER);
    }
 

I am trying to find piece of code which can tell me whether the android phone has GPS device or not? Most of the samples I am getting in search results are telling whether GPS is enabled or not. What I am interested in is whether Android phone has Physical GPS device or not?

Thanks

解决方案

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);
    }

这篇关于如何检查手机是否有GPS设备或没有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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