[英]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.