Reputation: 1
how can I detect automaticlly that a mobile is equipped by a GPS system or no? I found tetsts that give if a GPS is closed or now but what I search is about detecting if GPS system exists or no
Upvotes: 0
Views: 78
Reputation: 135
Try this code :
// getting GPS status
LocationManager locationManager = (LocationManager) mContext
.getSystemService(LOCATION_SERVICE);
isGPSEnabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
Hope this helps
Try this code to find whether GPS exists :
PackageManager pm= this.getPackageManager();
boolean hasGps =pm.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
Upvotes: -2
Reputation: 29722
If you want to only install on devices with GPS, then you have options in your manifest, which the Play store implements.
Check the Android Developer section on uses-feature
here:
This is the code you would put into your manifest.
<uses-feature
android:name="android.hardware.location.gps"
android:required="true" />
The Play store would only make this app available to devices that have GPS.
Note that the Android system itself does nothing with this information, it is only for the Play store.
However, if you want a runtime check, then I recommend @Biraj's or @OrhanC1's. They should both accomplish what you need, in slightly different ways.
Upvotes: 0
Reputation: 28484
Do this way
PackageManager pmanager = getPackageManager();
boolean hasGps = pmanager.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
if(hasGps){
// gps is available
}else{
// gps is not available
}
Upvotes: 2
Reputation: 1410
Call LocationManager.getAllProviders()
and check whether LocationManager.GPS_PROVIDER
is in the list.
Upvotes: 1