Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The device includes a light sensor.
Constant Value: "android.hardware.sensor.light"
Constant Value: "android.hardware.sensor.light"
* For API Level 3 and above, you may also use How to Determine if Android Device has Light Sensor, using SensorManager
1. Get a PackageManager Instance named myPackageManager.
1. Get a PackageManager Instance named myPackageManager.
2. Create a Boolean Variable named bolLightSupported.
3. Set the Minimum and Target SDK version to 7 or greater.
4. In the onCreate method, add the below code. This will return the light sensor availability to a boolean named bolLightSupported. It will then display a toast displaying the light sensor availability of the device to the user.
bolLightSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_LIGHT);
if (bolLightSupported) {
Toast.makeText(this, "Device has a Light Sensor", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Device does NOT have a Light Sensor!", Toast.LENGTH_LONG).show();
}
5. Compile and run!
Resources:
http://developer.android.com/reference/android/content/pm/PackageManager.html#FEATURE_SENSOR_LIGHT
http://developer.android.com/reference/android/content/pm/PackageManager.html#FEATURE_SENSOR_LIGHT