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

与世无争的帅哥 提交于 2020-01-01 03:21:12

问题


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


回答1:


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



回答2:


Starting with API level 8 (Froyo), you can use the following code:

PackageManager packageManager = mContext.getPackageManager();
boolean hasGPS = packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);


来源:https://stackoverflow.com/questions/6664355/how-can-i-check-whether-the-phone-has-gps-device-or-not

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!