Emulate Phone with no Camera?


If I setup an AVD with front and back phones set to NONE, the code that checks for FEATURE_CAMERA or FEATURE_CAMERA_FRONT still passes. and the button stays enabled. However, when I click the button I get an exception. So, it seems the PackageManager checks do not agree with the emulator settings. So, I tried to find a device that doesn’t have a camera. None of the devices you can select are camera-less.

Did Google make a phone that supports API 8+ that does not have a camera? Can we test this?



I’ve been tooking around with this for like fifteen minutes now, and I can’t for the life of me seem to create an AVD that will either fail these tests or generate an exception.

My suspicion is that we need to throw Camera.getNumberOfCameras() into the mix here, but until I can replicate the issue (which, again - doesn’t make sense that I can’t) I can’t say for sure what my recommendation is. If you can share your AVD configuration that generated the exception, it’d be very helpful.


The AVD was just a “Galaxy Nexus (4.65” … ", where Front and Back Camera are set to None. It is set for “Google APIs … 17”.


EDIT: It does not throw an exception and continues as if I set the front camera to Emulated, for the “3.4” WQVGA …" device with “Android 2.2 - API Level 8” AVD. Also, changing the Galaxy Nexus one still throws the exception if I switch to the latest Android API (4.2.2 - API 17).


I don’t have a good answer re: getting a good emulator to test this with. The best I can do is provide my recommendation for modified code to handle what the emulator is throwing at us:

        // if camera is not available, disable camera functionality
        PackageManager pm = getActivity().getPackageManager();
        boolean hasACamera = pm.hasSystemFeature(PackageManager.FEATURE_CAMERA) ||
                pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT) || 
                Camera.getNumberOfCameras() > 0;
        if (!hasACamera) {

I’ll add it to the errata.


Thanks. But, if every device that supports API 8+ has a camera, why bother checking?

What if we handled the RuntimeException thrown by the Camera.open() command? That command is in CrimeCameraFragment.onResume() now. Maybe we add an alternate layout, like an error messagebox, that gets displayed (inflated) when this error occurs?


The variety of Android devices out there is astounding. I couldn’t think of one off the top of my head, but I am not at all surprised to find that not every 8+ device has a camera: http://asia.cnet.com/roundup-android-smartphones-without-cameras-62219986.htm

That workaround sounds fine to me, if a bit janky. Well-behaved devices (which our emulators aren’t) shouldn’t be advertising that they have cameras, anyway, so I don’t expect that it would be seen too often by users in the wild.