Reputation: 4482
I am not sure why I am getting an error.
Camera error Can't connect to the camera.
Here is my code for the intent (and yes I have the permission in the manifest file)
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);
Here is the logcat error:
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)
Upvotes: 0
Views: 1953
Reputation: 1007534
If a camera app crashes, it can lock up the camera hardware, preventing it from being used again until the device is rebooted. Hence, if you run into "cannot open camera" and similar sorts of messages, try rebooting the device to see if the problem clears up.
Upvotes: 1