How to use Multi-Camera API with Samsung device?

620 views Asked by At

I’m trying to use the multi-camera api in a Samsung Galaxy A32 and S20 but I didn’t get any Logical Camera from the cameraIdList. Have anyone tried this API and received any Logical Camera?

This is the MainActivity.kt:

class MainActivity : AppCompatActivity() {

    private lateinit var binding : ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)

        if(!CameraPermissionHelper.hasCameraPermission(this)){
            CameraPermissionHelper.requestCameraPermission(this)
            return
        }

        startCameraSession()

    }

private fun startCameraSession(){

        val cameraManager : CameraManager = getSystemService(Context.CAMERA_SERVICE) as CameraManager

        if(cameraManager.cameraIdList.isEmpty()){
            Toast.makeText(applicationContext, "There is not any camera", Toast.LENGTH_SHORT).show()
            return
        }

for (s in cameraManager.cameraIdList) {
            val characteristics = cameraManager.getCameraCharacteristics(s)
            val capabilities = characteristics.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES)!!.contains(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA)
            if(capabilities){
                Log.i("TEST_CAMERA", "This is a Logical Camera $s")
            }else{
                Log.e("TEST_CAMERA", "No Logical Camera $s")
            }
        }
}

object CameraPermissionHelper{
        private const val CAMERA_PERMISSION_CODE = 0
        private const val CAMERA_PERMISSION = android.Manifest.permission.CAMERA

        fun hasCameraPermission(activity: Activity): Boolean{
            return ContextCompat.checkSelfPermission(activity, CAMERA_PERMISSION) == PackageManager.PERMISSION_GRANTED
        }

        fun requestCameraPermission(activity: Activity){
            ActivityCompat.requestPermissions(activity, arrayOf(CAMERA_PERMISSION), CAMERA_PERMISSION_CODE)
        }

        fun shouldShowRequestPermissionRationale(activity: Activity): Boolean{
            return ActivityCompat.shouldShowRequestPermissionRationale(activity, CAMERA_PERMISSION)
        }

        fun launchPermissionSetting(activity: Activity){
            val intent = Intent()
            intent.action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
            intent.data = Uri.fromParts("package", activity.packageName, null)
            activity.startActivity(intent)
        }
    }

    override fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<out String>,
        grantResults: IntArray
    ) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
        if (!CameraPermissionHelper.hasCameraPermission(this)){
            Toast.makeText(this, "Camera permission is needed to run this application", Toast.LENGTH_LONG).show()
            if (!CameraPermissionHelper.shouldShowRequestPermissionRationale(this)){
                CameraPermissionHelper.launchPermissionSetting(this)
            }
            finish()
        }
        recreate()
    }
}

I used minSDK 29. Another thing is when I use A32, I only get access to 3 cameras. But the CameraGlobalManager in the console shows more than 3 cameras, I don't understand why this is happening.

Console output:

0

There are 0 answers