Programmatically find device support GPS or not?
Yes, this can be done.
You can call LocationManager.getAllProviders()
and check whether LocationManager.GPS_PROVIDER
is included in the list.
Just for reference, I believe all released Android phones come with a GPS. It's not something that Android seem to be worrying about, e.g. mentioning GPS as one of the device attributes returned by PackageManager.getSystemAvailableFeatures()
.
Those methods are easier to use:
private boolean hasGpsSensor(){
PackageManager packMan = getPackageManager();
return packMan.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
}
true
: available (activated or not)false
: not available
So, in case of true
, we can use
private boolean isGpsEnabled(){
LocationManager manager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
return manager.isProviderEnabled(LocationManager.GPS_PROVIDER);
}
true
: enabledfalse
: disabled
With this two, you will know if GPS is available, activated or deactivated
There's also LocationManager.isProviderEnabled(String provider) method.