In my app, I'd like to use the camera, if the device has one. Are there any devices running android that do not have a camera? By including the following into my manifest:
<uses-feature android:name="android.hardware.camera" android:required="false"/>
then it's basically saying "I'll use a camera if one exists, but don't need one to run the app".
How could I check if a camera exists on the device, before attempting to use the Camera class?
In Android, you can use PackageManager , hasSystemFeature() method to check if a device has camera, gps or other features. See full example of using PackageManager in an activity class.
Open the app and swipe to the Camera tab. Here, look under the Hardware– you'll see all the image sensors used on the phone. Furthermore, it'll also show you other details like resolution, aperture, focal length, sensor size, pixel size, and more.
Still unable to access you front or rear camera on Android phone? Try this! Go to SETTINGS > APPS & NOTIFICATIONS (select, “See all Apps”) > scroll to CAMERA > tap FORCE STOP, and then OK. Navigate back to your Home Screen, and launch the Camera app again to check that it works.
This is what I'm using
import android.content.pm.PackageManager; PackageManager pm = context.getPackageManager(); if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) { }
All sorts of other fun things to test for are available too - the compass, is location available, is there a front facing camera: http://developer.android.com/reference/android/content/pm/PackageManager.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With