private void takePicture(ImageCapture imageCapture) {
File file = new File("/sdcard/screenShot/", "111.jpg");
ImageCapture.OutputFileOptions outputFileOptions = new ImageCapture.OutputFileOptions.Builder(file).build();
imageCapture.takePicture(outputFileOptions, ContextCompat.getMainExecutor(this), new ImageCapture.OnImageSavedCallback() {
@Override
public void onImageSaved(@NonNull ImageCapture.OutputFileResults outputFileResults) {
Log.d(TAG, "onImageSaved: ");
// TODO: 5/14/21 保存成功
}
@Override
public void onError(@NonNull ImageCaptureException exception) {
Log.d(TAG, "onError: "+exception.getMessage());
}
});
}
调用拍照,报错
onError: Capture request failed with reason ERROR
解决方法
打开AndroidManifest.xml并将这些行添加到application标记之前。
<uses-feature android:name="android.hardware.camera.any" />