Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if device has a camera?

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?

like image 631
mark Avatar asked Dec 22 '09 04:12

mark


People also ask

How do I know if my Android has a camera?

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.

How do I find my camera on a device?

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.

How do I find the front camera on my Android?

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.


1 Answers

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

like image 123
dpjanes Avatar answered Oct 02 '22 21:10

dpjanes