Android

Android 取得手機調用Camera1或是Camera2的相機硬體

1.導入SDK到專案中

dependencies {
    implementation 'co.infinum:goldeneye:1.1.2'
}

2.初始化GoldenEye

GoldenEye goldenEye = new GoldenEye.Builder(activity).build();

3.取得可用的相機並設為變數之後好判斷

Java

private String useCamera;
    CameraInfo cameraInfo = goldenEye.getAvailableCameras().get(0);
    if (cameraInfo.toString().contains("camera2")) {
          useCamera = "camera2";
    } else {
          useCamera = "camera1";
    }

Kotlin

private lateinit var useCamera: String
val goldenEye = GoldenEye.preferredCameraApi(this)
useCamera = goldenEye.toString().toLowerCase(Locale.ROOT)

發表迴響