我收到一些用户的报告,但有以下例外情况
java.lang.IllegalArgumentException:getCameraCharacteristics:1019: 无法检索未知设备的相机特征 0:否 此类文件或目录 (-2) 位于 android.hardware.camera2.CameraManager.throwAsPublicException(CameraManager.java:1591) 在 android.hardware.camera2.CameraManager.getCameraCharacteristics(CameraManager.java:693)
这当然没有任何意义,因为我们都知道id为“0”的相机应该可用。无论如何,我有有关设备相机的信息包含在报告中:
Camera ID: 0 (selected), all [0, 2, 1, 3]
Cameras level: FULL, LIMITED, LIMITED, LIMITED
所以系统似乎有时会认为这样的相机不可用并触发这个恼人的异常。
有一件事我可以说这个问题只发生在 Android 12 上......
如果你在 Flutter 上写作,它对我有用!
Android(AndroidManifest.xml):
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>
android/app/src/main/kotlin/com/example/projcet_name/MainActivity.kt
package com.example.wow_person_live
import android.Manifest
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.webkit.PermissionRequest
import android.webkit.WebChromeClient
import android.webkit.WebView
import androidx.annotation.NonNull
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterActivity() {
private val CAMERA_PERMISSION_REQUEST_CODE = 1
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Проверка и запрос разрешений на камеру и микрофон
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO), CAMERA_PERMISSION_REQUEST_CODE)
}
}
val webView = WebView(this)
webView.webChromeClient = object : WebChromeClient() {
override fun onPermissionRequest(request: PermissionRequest) {
// Автоматическое предоставление всех запрошенных разрешений
request.grant(request.resources)
}
}
setContentView(webView)
}
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine)
}
}
这对我有用,干得好,兄弟!