gpt4 book ai didi

java - 接收 CameraAccessException : CAMERA_ERROR (3) on CaptureSession. setRepeatingRequest()

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:34:01 26 4
gpt4 key购买 nike

我从 onCreate() 方法运行以下代码。这段代码之外只是许多对象声明和回调的实例化。

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

thisAct = this;
display = (TextureView)findViewById(R.id.display);
display.setSurfaceTextureListener(surfaceTextureListener);

db = openOrCreateDatabase("MyDatabase", Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS Photos (ID INTEGER, location TEXT, size INTEGER)");
db.execSQL("CREATE TABLE IF NOT EXISTS Tags (ID INTEGER, tag TEXT)");

camMan = this.getSystemService(CameraManager.class);

new Thread(new Runnable(){
@Override
public void run() {
try {
String cm = camMan.getCameraIdList()[0];

if ( ContextCompat.checkSelfPermission(thisAct, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED ) {
ActivityCompat.requestPermissions((Activity)thisAct, new String[] { Manifest.permission.CAMERA }, CAMERA_REQUEST);
}
camMan.openCamera(cm, CDstateCallback, handle);

while(texture == null){
try{
Thread.sleep(100);
Log.v("DEBUG!!!!!!!!", "Thread sleeping b/c texture is null");
} catch(Exception e){
e.printStackTrace();
}
}

// texture.setDefaultBufferSize(325,325);
Surface s = new Surface(texture);
surfaceList.add(s);

while(cameraDevice == null){
try{
Thread.sleep(100);
Log.v("DEBUG!!!!!!!!", "Thread sleeping b/c cameraDevice is null");
} catch(Exception e){
e.printStackTrace();
}
}

cameraDevice.createCaptureSession(surfaceList, CCSstateCallback, handle);

while(capSess == null){
try{
Thread.sleep(100);
Log.v("DEBUG!!!!!!!!", "Thread sleeping b/c capSess is null");
} catch(Exception e){
e.printStackTrace();
}
}

capSess.prepare(surfaceList.get(0));

capReq = cameraDevice.createCaptureRequest(cameraDevice.TEMPLATE_PREVIEW);
capReq.addTarget(surfaceList.get(0));
capSess.setRepeatingRequest(capReq.build(), CCSlistener, handle);

} catch (CameraAccessException e) {
e.printStackTrace();
}
}
}).start();
}

执行此行时,我在控制台中收到以下错误:

capSess.setRepeatingRequest(capReq.build(), CCSlistener, handle);

.

android.hardware.camera2.CameraAccessException: CAMERA_ERROR (3): submitRequestList:257: Camera 0:  Got error Invalid argument (-22) after trying to set streaming request

在网上搜索了一下,似乎是指"ERROR_CAMERA_DISABLED"代码,表示由于设备策略,无法打开相机设备。

这最初让我想到直接查看权限,但如行中所示:

if ( ContextCompat.checkSelfPermission(thisAct, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED ) {
ActivityCompat.requestPermissions((Activity)thisAct, new String[] { Manifest.permission.CAMERA }, CAMERA_REQUEST);
}

,

我会检查权限并在应用尚无权限时提示用户提供权限。我还在 list 文件和设备上检查了我的应用程序设置,以确认我确实拥有相机硬件权限。谁能帮我解决这个问题?

最佳答案

添加这段代码来处理小于 25 的 API 为我解决了这个问题。

if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N) {
mCaptureSession.stopRepeating();
mCaptureSession.abortCaptures();
}
mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);

关于java - 接收 CameraAccessException : CAMERA_ERROR (3) on CaptureSession. setRepeatingRequest(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47148422/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com