我不确定为什么会收到错误。
相机错误 无法连接相机。
这是我的意图代码(是的,我在清单文件中有权限)
final File root = new File(Environment.getExternalStorageDirectory() + File.separator + "MyDir" + File.separator);
root.mkdirs();
final String fname = getUniqueImageFilename();
final File sdImageMainDirectory = new File(root, fname);
outputFileUri = Uri.fromFile(sdImageMainDirectory);
// Camera.
final List<Intent> cameraIntents = new ArrayList<Intent>();
final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
final PackageManager packageManager = getActivity().getPackageManager();
final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
for (ResolveInfo res : listCam) {
final String packageName = res.activityInfo.packageName;
final Intent intent = new Intent(captureIntent);
intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
intent.setPackage(packageName);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
cameraIntents.add(intent);
}
final Intent chooserCameraIntent = Intent.createChooser(captureIntent, "Use Camera");
startActivityForResult(chooserCameraIntent, YOUR_SELECT_PICTURE_REQUEST_CODE);
这是logcat错误:
03-12 00:34:49.038 183-838/? E/mm-camera-intf﹕ mm_camera_open: dev name = /dev/video1, cam_idx = 1
03-12 00:34:54.038 183-838/? E/mm-camera-intf﹕ mm_camera_open: opened, break out while loop
03-12 00:34:54.038 183-838/? E/mm-camera-intf﹕ mm_camera_open: cannot open control fd of '/dev/video1' (Connection timed out)
03-12 00:34:54.038 183-838/? E/mm-camera-intf﹕ camera_open: mm_camera_open err = -1
03-12 00:34:54.038 183-838/? E/QCamera3HWI﹕ camera_open failed.
03-12 00:34:54.038 183-838/? E/Camera3-Device﹕ Camera 0: initialize: Could not open camera: Unknown error -2147483648 (-2147483648)
03-12 00:34:54.038 183-838/? E/Camera2ClientBase﹕ initialize: Camera 0: unable to initialize device: Unknown error -2147483648 (-2147483648)
03-12 00:34:54.048 24562-24562/? E/CameraHolder﹕ fail to connect Camera:-1, aborting.
03-12 00:34:54.048 24562-24562/? E/CAM_PhotoModule﹕ Failed to open camera:0
03-12 00:36:49.658 768-846/? E/InputDispatcher﹕ channel '434c3678 com.example.app/com.example.app.Home (server)' ~ Channel is unrecoverably broken and will be disposed!
03-12 00:36:50.048 183-26193/? E/ACDB-LOADER﹕ Error: ACDB AudProc vol returned = -19
03-12 00:36:50.378 24562-24562/? E/WindowManager﹕ android.view.WindowLeaked: Activity com.android.camera.CameraActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{42a40b28 V.E..... R....... 0,0-1026,584} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:348)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.Dialog.show(Dialog.java:286)
at android.app.AlertDialog$Builder.show(AlertDialog.java:951)
at com.android.camera.util.CameraUtil.showErrorAndFinish(CameraUtil.java:357)
at com.android.camera.CameraActivity$2.onDeviceOpenFailure(CameraActivity.java:247)
at com.android.camera.AndroidCameraManagerImpl$CameraOpenErrorCallbackForward$2.run(AndroidCameraManagerImpl.java:845)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
如果相机应用程序崩溃,它可能会锁定相机硬件,防止在设备重新启动之前再次使用它。因此,如果遇到&#34;无法打开相机&#34;和类似的消息,尝试重新启动设备,看看问题是否清除。