2014-04-18 143 views
0

如何自动检测手机是否配备GPS系统?我发现,如果GPS关闭或现在,但是我搜索的东西是关于检测GPS系统是否存在或不存在自动检测GPS

+0

您是否试图避免在没有GPS的设备上安装?或者这只是您希望在运行时执行的检查? –

回答

1

请致电LocationManager.getAllProviders()并检查LocationManager.GPS_PROVIDER是否在列表中。

2

做这样

PackageManager pmanager = getPackageManager(); 
boolean hasGps = pmanager.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS); 

if(hasGps){ 
    // gps is available 
}else{ 
    // gps is not available 
} 
+0

我想我其实更喜欢这个!如果GPS处于活动状态,则返回 – OrhanC1

-2

试试这个代码:

// getting GPS status 
     LocationManager locationManager = (LocationManager) mContext 
       .getSystemService(LOCATION_SERVICE); 
     isGPSEnabled = locationManager 
       .isProviderEnabled(LocationManager.GPS_PROVIDER); 

希望这有助于

试试这个代码,以查找GPS是否存在:

  PackageManager pm= this.getPackageManager(); 
      boolean hasGps =pm.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS); 
+0

。它无助于确定设备上是否存在GPS,但是已关闭。 –

0

如果您只想在设备机器上安装h GPS,那么您的清单中有Play选项,

检查uses-feature这里的Android开发者部分:

这是你把你的清单中的代码。

<uses-feature 
    android:name="android.hardware.location.gps" 
    android:required="true" /> 

Play商店只会让此应用可用于具有GPS的设备。

请注意,Android系统本身对此信息不做任何处理,它仅适用于Play商店。

但是,如果您想要运行时检查,那么我推荐@Biraj's@OrhanC1's。他们都应以完全不同的方式完成你所需要的。