Java tutorial
//package com.java2s; import android.content.Context; import android.content.pm.PackageManager; import android.os.Build; public class Main { /** * @param context * the application context * @return true if the device has any camera, false else */ public static boolean hasCameraAny(Context context) { if (hasCameraBack(context) || hasCameraFront(context)) { return true; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { PackageManager pm = context.getPackageManager(); return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY); } return false; } /** * @param context * the application context * @return true if the device has a rear camera, false else */ public static boolean hasCameraBack(Context context) { PackageManager pm = context.getPackageManager(); return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA); } /** * @param context * the application context * @return true if the device has a front camera, false else */ public static boolean hasCameraFront(Context context) { PackageManager pm = context.getPackageManager(); return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT); } }