Intent方式打开前置摄像头

作者: nickieeee | 来源:发表于2020-02-09 00:29 被阅读0次

已经失效的方法

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (front) {
    intent.putExtra("android.intent.extras.CAMERA_FACING", 1);
}
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(targetFile));
startActivityForResult(this, intent, requestCode);


正确打开前置摄像头的姿势

Intent intent;
if (front) {
    intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
    intent.putExtra("android.intent.extras.CAMERA_FACING", android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT);
    intent.putExtra("android.intent.extras.LENS_FACING_FRONT", 1);
    intent.putExtra("android.intent.extra.USE_FRONT_CAMERA", true);
} else{
    intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
}
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(targetFile));
startActivityForResult(this, intent, requestCode);

关键在于需要使用MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA

相关文章

网友评论

    本文标题:Intent方式打开前置摄像头

    本文链接:https://www.haomeiwen.com/subject/cyawxhtx.html