0

I'm trying to determine whether a particular Android device has a camera. The documentation for the android.hardware.Camera.open() states

Creates a new Camera object to access the first back-facing camera on the device. If the device does not have a back-facing camera, this returns null.

The Kindle I am testing on (first generation I believe) does not have any camera, and yet open() is returning non-null. Why is that? Perhaps because Amazon runs a forked version of Android with different behavior? Is there another way to determine whether or not the device has a camera?

Peter Jacobs
  • 1,657
  • 2
  • 13
  • 29

1 Answers1

1

Maybe this can help you

/**
 * Determines if the current device can handle an image capture action.
 * @return true if the device can handle an image capture action. False if it cannot.
 */
protected boolean canHandleCameraIntent() {
  final Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
  final List<ResolveInfo> results = getPackageManager().queryIntentActivities(intent, 0);
  return (results.size() > 0);            
}

more content at https://developer.amazon.com/sdk/fire/specifications.html

Update

I can't test that for you, but I think this could also help you

http://developer.android.com/reference/android/content/pm/PackageManager.html

PackageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
GhostDerfel
  • 1,533
  • 1
  • 11
  • 18
  • The OP is using `android.hardware.Camera` to work with the camera directly, not via a third-party app. – CommonsWare Nov 28 '13 at 19:27
  • but with this function he can continue to work with the camera directly if the camera exists on kindle , no? – GhostDerfel Nov 28 '13 at 19:32
  • @PeterJacobs Can you try with PackageManager also? :) I think it's the best way to solve the problem (if this works with Kindle) – GhostDerfel Nov 28 '13 at 19:39
  • Yes, I am using your code solution with PackageManager, thanks!. – Peter Jacobs Nov 28 '13 at 19:41
  • Oh, I didn't see the second one at first. Yes, both work, but of course the 2nd one is only one line of code, so I'll go with that one. Thanks again for your answer! – Peter Jacobs Nov 28 '13 at 20:20
  • Still, strange that the Android documentation is wrong re: Camera.open(). Also wrong is android.hardware.Camera.Parameters.getFlashMode(), which the docs state never returns null, when in fact, it does return null when run on the Kindle 1st generation. Must be Amazon's doing. :-) – Peter Jacobs Nov 28 '13 at 20:28
  • 1
    Actually, I discovered an issue with the second solution. It is only supported as of SDK 17 (4.2), and I need to support Android versions previous to 4.2. If SDK < 17, PackageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY) just returns false regardless of whether or not there is a camera! Very misleading. – Peter Jacobs Dec 03 '13 at 23:49