android - 选择前置摄像头

标签 android android-camera

<分区>

我正在使用以下代码拍照:

private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
            //...
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                    Uri.fromFile(photoFile));
            startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
        }
    }
}

有没有办法选择前置摄像头?

最佳答案

你可以试试这个。

takePictureIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);

但并非所有相机应用程序都支持该标志

关于android - 选择前置摄像头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31857211/

相关文章:

Android:获取错误:转换为 Dalvik 格式失败

android - Wowza 示例链接在 android 中不起作用

android - 将 FFMpeg 视频转换为 android 可播放视频

java - Android java.lang.RuntimeException : Unable to instantiate activity ComponentInfo com. aksitrewari.gateexampreparation.MyActivity

java - 无论我做什么,我都无法保存相机捕获的图像。我该怎么做?

android - 保存在 ImageView 中时,从自定义相机拍摄的图像会被拉伸(stretch)

android - 停止后MediaPlayer无法播放

android - 图像分析库/功能

android - 正确处理异常 : "getParameters failed (empty parameters)"

android - 无法使用 HttpClient 从 Android 设备相机发布图像