How do you check if the device has a camera with reflection?
<p>I'm adapting an app so it will work on the KindleFire, which doesn't have a camera.</p>

<p>I don't have any Android devices that lack a camera, so I don't know if the following code actually will <code>return false</code> for the Kindle.  I'm using reflection because my app has already been released with Donut compatibility, and Donut doesn't have <code>PackageManager.hasSystemFeature()</code>.</p>

<p>I'm assuming Donut devices all have cameras--hasn't caused me trouble yet.</p>

<pre><code>public static boolean isCameraAvailable(Context context){
    PackageManager pm = context.getPackageManager();
    return tryHasSystemFeature(pm,"android.hardware.camera");
}

private static Method packageManager_hasSystemFeature;

static {
    initCompatibility();
};

private static void initCompatibility() {
    try {
        packageManager_hasSystemFeature = PackageManager.class.getMethod(
                "hasSystemFeature", new Class[] { String.class } );
    } catch (NoSuchMethodException nsme) {
        //leave the Method null
    }
}

static private boolean tryHasSystemFeature(PackageManager pm,String feature){
    if (packageManager_hasSystemFeature != null) {
        try {
            final Boolean hasIt = (Boolean) packageManager_hasSystemFeature.invoke(pm,feature);
            return hasIt.booleanValue();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        }
    }
    return true;
}
</code></pre>
