我\xc2\xb4m 尝试编写我的第一个Android 相机应用程序,但它总是选择变焦相机而不是主相机。(我在华为P30 Pro上测试过)
\n\n该代码基于官方的camerax示例应用程序(https://github.com/android/camera-samples/tree/master/CameraXBasic)
\n\n相关代码:
\n\n/** Declare and bind preview, capture and analysis use cases */\nprivate fun bindCameraUseCases() {\n\n // Get screen metrics used to setup camera for full screen resolution\n val metrics = DisplayMetrics().also { viewFinder.display.getRealMetrics(it) }\n Log.d(TAG, "Screen metrics: ${metrics.widthPixels} x ${metrics.heightPixels}")\n\n val screenAspectRatio = aspectRatio(metrics.widthPixels, metrics.heightPixels)\n Log.d(TAG, "Preview aspect ratio: $screenAspectRatio")\n\n val rotation = viewFinder.display.rotation\n\n // Bind the CameraProvider to the LifeCycleOwner\n\n val cameraSelector = CameraSelector.Builder().requireLensFacing(lensFacing).build()\n\n val cameraProviderFuture = ProcessCameraProvider.getInstance(requireContext())\n cameraProviderFuture.addListener(Runnable …Run Code Online (Sandbox Code Playgroud)