解决Android open failed: EACCES (Permission denied)

Android6.0以上会报这个错,添加一下红色代码即可

public class ABCActivity extends AppCompatActivity implements View.OnClickListener,
        SurfaceHolder.Callback, PictureCallback, AutoFocusCallback {
    public static int Desired_Preview_Width = 1280;
    public static int Desired_Preview_Height = 720;
    public static int Desired_Picture_Width = 1280;
    public static int Desired_Picture_Height = 960;

    private SurfaceView mVideoView = null;
    private SurfaceHolder mHolder = null;
    private Camera mCamera = null;
    //
    private ImageView mBtnCapture = null;

    //超时计时
    private Timer mTimer = null;
    private Handler mMsgHandler = null;
    private int mCounter = 0;

    //对焦超时为2秒
    private static final int Timeout = 2;
    private TextView tv = null;
    private ProgressBar btn_wait = null;
    private static final int REQUEST_EXTERNAL_STORAGE = 1;
    private static String[] PERMISSIONS_STORAGE = {
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE };

    public static void verifyStoragePermissions(Activity activity) {
        // Check if we have write permission
        int permission = ActivityCompat.checkSelfPermission(activity,
                Manifest.permission.WRITE_EXTERNAL_STORAGE);
        if (permission != PackageManager.PERMISSION_GRANTED) {
            // We don't have permission so prompt the user
            ActivityCompat.requestPermissions(activity, PERMISSIONS_STORAGE,
                    REQUEST_EXTERNAL_STORAGE);
        }
    }

    @SuppressLint("HandlerLeak")
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        verifyStoragePermissions(this);

        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        if (findViewById(R.id.textView1) != null)
            tv = findViewById(R.id.textView1);

        if (findViewById(R.id.btn_wait) != null)
            btn_wait = findViewById(R.id.btn_wait);

你可能感兴趣的:(Android)