I need to check if the GPS system is present on an android device.
I have seen the reply to the following question ,
How to check for the presence of a GPS sensor? ,but need to do it with an API level of 3 or 4.
The answer present on the link will work with a minimum of API Level of 5 for
hasSystemFeature() and 8 for the PackageManager.FEATURE_LOCATION_GPS constant.
Thanks in advance.
Update :
Used the following code, implementing the solution from CommonsWare.
boolean gpsOnBoard;
LocationManager locMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE);
List<String> locProvs = locMan.getProviders(true);
// check if we have a valid list of providers
if (locProvs != null)
{
gpsOnBoard = false;
// check all providers
for (String locProvName:locProvs)
{
if (locProvName.equals(LocationManager.GPS_PROVIDER))
{
// we have GPS hw onboard
gpsOnBoard = true;
}
}
Call
getProviders()on theLocationManagerand see what providers are there.Ideally, you do not hard-code GPS support in your app, as users might have that provider disabled, even if the hardware exists. Consider using
Criteriaand another flavor ofgetProviders()to allow Android to help you find an appropriate and available provider.