簡體   English   中英

Android攝像頭意圖打開前置攝像頭而不是后置攝像頭

[英]Android camera intent open front camera instead of back camera

我正面臨一個奇怪的問題,向移動相機發送意圖拍照。 在我的手機中,xaomi 8 運行良好,但是當我在 samsung a 51 上安裝應用程序時,意圖打開前置攝像頭而不是后置攝像頭。 目標始終是在所有類型的移動設備上打開后置攝像頭。 這是我的代碼

cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
if (cameraIntent.resolveActivity(getPackageManager()) != null) {
  startActivityForResult(cameraIntent, ApplicationConst.CodiceIntentConst.REQUEST_CAMERA_CODE);
}

我該如何解決? 先感謝您

以下代碼適用於Samsung A51Pixel 2XL

fun updateIntentForCameraFacing(cameraIntent: Intent, frontFacing: Boolean){
    if(Build.VERSION.SDK_INT < Build.VERSION_CODES.O){
        if(frontFacing)
            cameraIntent.putExtra("android.intent.extras.CAMERA_FACING", CameraCharacteristics.LENS_FACING_BACK)
        else
            cameraIntent.putExtra("android.intent.extras.CAMERA_FACING", CameraCharacteristics.LENS_FACING_FRONT)

    }
    else if(frontFacing){
        cameraIntent.putExtra("android.intent.extras.CAMERA_FACING", CameraCharacteristics.LENS_FACING_BACK)
        cameraIntent.putExtra("android.intent.extra.USE_FRONT_CAMERA", true)

        //samsung
        cameraIntent.putExtra("camerafacing", "front")
        cameraIntent.putExtra("previous_mode", "front")
    }
    else{
        cameraIntent.putExtra("android.intent.extras.CAMERA_FACING", CameraCharacteristics.LENS_FACING_FRONT)
        cameraIntent.putExtra("android.intent.extra.USE_FRONT_CAMERA", false)

        //samsung
        cameraIntent.putExtra("camerafacing", "rear")
        cameraIntent.putExtra("previous_mode", "rear")
    }
}

我正面臨一個奇怪的問題,向移動相機發送意圖拍照。 在我的手機中,xaomi 8 運行良好,但是當我在 samsung a 51 上安裝應用程序時,意圖打開前置攝像頭而不是后置攝像頭。 目標始終是在各種移動設備上打開后置攝像頭。 這是我的代碼Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); if (cameraIntent.resolveActivity(getPackageManager()) != null) { startActivityForResult(cameraIntent, ApplicationConst.CodiceIntentConst.REQUEST_CAMERA_CODE);} Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); if (cameraIntent.resolveActivity(getPackageManager()) != null) { startActivityForResult(cameraIntent, ApplicationConst.CodiceIntentConst.REQUEST_CAMERA_CODE);}

我該如何解決? 先感謝您

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM