is Camera Has Permission - Android Camera

Android examples for Camera:Camera Feature

Description

is Camera Has Permission

Demo Code


import android.hardware.Camera;
import java.lang.reflect.Field;

public class Main{
    /*from   w  ww.j av a  2s .co  m*/
    public static boolean isCameraHasPermission(Camera camera) {
        if (camera == null) {
            return false;
        }

        Class cameraClass = (Class) camera.getClass();
        if (cameraClass == null) {
            return false;
        }

        try {
            Field[] fs = cameraClass.getDeclaredFields();
            if (fs != null) {
                for (int i = 0; i < fs.length; i++) {
                    Field f = fs[i];
                    try {
                        f.setAccessible(true);
                        Object val = f.get(camera);
                        if ("mHasPermission".equals(f.getName())
                                && val instanceof Boolean) {
                            L.d("CameraUtils isCameraHasPermission",
                                    "name:" + f.getName() + "\t value = "
                                            + val);
                            return (boolean) val;
                        }
                    } catch (Exception e) {
                        // no op
                    }
                }
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return true;
        }
    }
}

Related Tutorials