Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The device has a Global Positioning System receiver and can report precise location.
Constant Value: "android.hardware.location.gps"
Constant Value: "android.hardware.location.gps"
1. Get a PackageManager Instance and save to myPackageManager.
2. Create a Boolean Variable named bolGPSSupported.
3. Set the Minimum and Target SDK version to 8 or greater.
4. In the onCreate method, add the below code. This will return the GPS ability to a boolean named bolGPSSupported. It will then display a toast displaying the GPS ability on the device to the user.
bolGPSSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
if (bolGPSSupported) {
Toast.makeText(this, "Device has GPS feature", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "No GPS feature!", Toast.LENGTH_LONG).show();
}
5. Compile and run!
Resources:
http://developer.android.com/reference/android/content/pm/PackageManager.html#FEATURE_LOCATION_GPS
Resources:
http://developer.android.com/reference/android/content/pm/PackageManager.html#FEATURE_LOCATION_GPS