Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to configure camera #132

Closed
ghost opened this issue Feb 5, 2016 · 14 comments
Closed

Failed to configure camera #132

ghost opened this issue Feb 5, 2016 · 14 comments
Milestone

Comments

@ghost
Copy link

ghost commented Feb 5, 2016

Camera not working when rotating device.
Used TextureView, Nexus 9 (API 23)
Logs
D/CameraInstance: Opening camera D/CameraInstance: Closing camera D/CameraInstance: Opening camera D/CameraInstance: Configuring camera I/CameraManager: Camera Display Orientation: 90 W/CameraManager: Failed to set rotation. W/CameraManager: Camera rejected even safe-mode parameters! No configuration E/CameraInstance: Failed to configure camera E/CameraInstance: java.lang.RuntimeException: getParameters failed (empty parameters) E/CameraInstance: at android.hardware.Camera.native_getParameters(Native Method) E/CameraInstance: at android.hardware.Camera.getParameters(Camera.java:1890) E/CameraInstance: at com.journeyapps.barcodescanner.camera.CameraManager.setParameters(CameraManager.java:365) E/CameraInstance: at com.journeyapps.barcodescanner.camera.CameraManager.configure(CameraManager.java:141) E/CameraInstance: at com.journeyapps.barcodescanner.camera.CameraInstance$4.run(CameraInstance.java:178) E/CameraInstance: at android.os.Handler.handleCallback(Handler.java:739) E/CameraInstance: at android.os.Handler.dispatchMessage(Handler.java:95) E/CameraInstance: at android.os.Looper.loop(Looper.java:148) E/CameraInstance: at android.os.HandlerThread.run(HandlerThread.java:61) E/Camera: Error 2 E/Camera: Error 2 E/Camera: Error 2 E/Camera: Error 2 D/CameraPreview: pause() D/CameraInstance: Closing camera

May be there is a way to use SurfaceView and set its size equal to BarcodeView's size, not large?
Thank you.

@rkistner
Copy link
Member

rkistner commented Feb 6, 2016

Should be fixed by #133.

@rkistner
Copy link
Member

rkistner commented Feb 6, 2016

The error should be fixed in v3.2.0. The release also contains better preview scaling logic and uses TextureView by default, which should solve the sizing issues.

Please re-open the issue if it is not solved yet.

@rkistner rkistner closed this as completed Feb 6, 2016
@ghost
Copy link
Author

ghost commented Feb 8, 2016

Everything work fine, but there is a bug on Android 6.0, when need to request permission. After permission granted camera not configure. Black window instead.

`<RelativeLayout
        android:layout_width="@dimen/scanner_width"
        android:layout_height="@dimen/scanner_height">

        <com.journeyapps.barcodescanner.BarcodeView
            android:id="@+id/zxing_barcode_surface"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:zxing_preview_scaling_strategy="centerCrop"
            app:zxing_use_texture_view="true" />
</RelativeLayout>`
`@Override
    public void onResume() {
        super.onResume();
        String cameraPermission = Manifest.permission.CAMERA;
        int permissionCheck = ContextCompat.checkSelfPermission(activity, cameraPermission);
        if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
            mBarcodeView.resume();
        } else {
            requestPermissions(new String[]{cameraPermission}, REQUEST_CAMERA);
        }
    }`
` @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        if (requestCode == REQUEST_CAMERA) {
            for (int i = 0; i < permissions.length; i++) {
                if (permissions[i].equals(Manifest.permission.CAMERA)
                        && grantResults[i] == PackageManager.PERMISSION_GRANTED) {
                    mBarcodeView.resume();
                }
            }
        }
    }
`

If reopen this activity, everything works fine.
There are no any warnings and errors in log.
Works fine with SurfaceView in this situation.

@rkistner
Copy link
Member

rkistner commented Feb 8, 2016

The library now has a built-in permission check.

Can you test what happens if you remove this permission check logic?

@ghost
Copy link
Author

ghost commented Feb 8, 2016

I used simple BarcodeView and without my permission check I receive an error

Failed to open camera E/CameraInstance: java.lang.RuntimeException: Fail to connect to camera service E/CameraInstance: at android.hardware.Camera.<init>(Camera.java:495) E/CameraInstance: at android.hardware.Camera.open(Camera.java:341) E/CameraInstance: at com.google.zxing.client.android.camera.open.OpenCameraInterface.open(OpenCameraInterface.java:83) E/CameraInstance: at com.journeyapps.barcodescanner.camera.CameraManager.open(CameraManager.java:123) E/CameraInstance: at com.journeyapps.barcodescanner.camera.CameraInstance$3.run(CameraInstance.java:165) E/CameraInstance: at android.os.Handler.handleCallback(Handler.java:739) E/CameraInstance: at android.os.Handler.dispatchMessage(Handler.java:95) E/CameraInstance: at android.os.Looper.loop(Looper.java:148) E/CameraInstance: at android.os.HandlerThread.run(HandlerThread.java:61) D/CameraInstance: Configuring camera E/CameraInstance: Failed to configure camera E/CameraInstance: java.lang.RuntimeException: Camera not open E/CameraInstance: at com.journeyapps.barcodescanner.camera.CameraManager.configure(CameraManager.java:142) E/CameraInstance: at com.journeyapps.barcodescanner.camera.CameraInstance$4.run(CameraInstance.java:178) E/CameraInstance: at android.os.Handler.handleCallback(Handler.java:739) E/CameraInstance: at android.os.Handler.dispatchMessage(Handler.java:95) E/CameraInstance: at android.os.Looper.loop(Looper.java:148) E/CameraInstance: at android.os.HandlerThread.run(HandlerThread.java:61)

@ghost
Copy link
Author

ghost commented Feb 8, 2016

As I found your check logic used on CaptureManager, which used on CameraActivity only. I dont use CameraActivity, just BarcodeView class.

@rkistner
Copy link
Member

rkistner commented Feb 8, 2016

You're right, I forgot that is only done in CaptureManager / CaptureActivity.

I'll look into this.

@rkistner rkistner reopened this Feb 8, 2016
@ghost
Copy link
Author

ghost commented Feb 8, 2016

Ok. thanks.

@Bajranghudda1
Copy link

@rkistner
I am using CompoundBarcodeView and i need to get permission too for android M, and i got same issue if i not use my own permission check but its working fine if i'm using my own check.
So will you update it so that we don't need to check for permission.

Thanks in advance.

@rkistner
Copy link
Member

The permission check is automatic if you use CaptureActivity. For CompoundBarcodeView there's not much that can be done in the library, since the permission request must happen on the Activity.

I'll see if I can find a way to simplify it a bit for the next release.

@ghost
Copy link
Author

ghost commented Feb 11, 2016

It's not a problem to write your own check logic. After permission granted camera not configure. Black window instead. I think you should fix this behavior, not permission build-in logic.

@rkistner
Copy link
Member

@ramanbranavitski Yes, I'm also looking into that. I haven't been able to reproduce it yet though. Can you reproduce that on an emulator? I don't have a physical device with Android 6 unfortunately.

@rkistner
Copy link
Member

Some bugs around permission handling may have been fixed since this issue was opened. Please create a new issue if this persists in v3.5.0.

@plswiderski
Copy link

Problem still occurs in v3.5.0 and Android 6 but you can easily fix this by dynamically adding CAMERA permission (https://developer.android.com/training/permissions/requesting.html)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants