lundi 13 juin 2016

How to set CAMERA permission in order to pass regular test?

It is a very strange situation. I am working with camera2 API and there is a regular method to open the camera.

manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler);

this method is requiring to make test, this one

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) !=
            PackageManager.
        return;
    }

it is simple test to deduce if there was declared Camera permission in manifest or not.

<uses-permission android:name="android.permission.CAMERA" />

i have this permission in my manifest file and if i am uploading this app to Samsung S5 it is work properly without problem, but if i am uploading this app to chinese device, mistake is happen. Don't pass the test and eventually don't open the camera...

Maybe should i set permission dynamically?

And one more thing, i have tryed call method to open the camera inside test, this way

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) !=
            PackageManager.
        manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler);
        return;
    }

but get this mistake

FATAL EXCEPTION: main Process: com.example.android.camera2basic, PID: 29649 Theme: themes:{} java.lang.SecurityException: Lacking privileges to access camera service at android.hardware.camera2.utils.CameraBinderDecorator.throwOnError(CameraBinderDecorator.java:108) at android.hardware.camera2.legacy.CameraDeviceUserShim.connectBinderShim(CameraDeviceUserShim.java:336) at android.hardware.camera2.CameraManager.openCameraDeviceUserAsync(CameraManager.java:327) at android.hardware.camera2.CameraManager.openCamera(CameraManager.java:457) at com.example.android.camera2basic.activities.CameraActivity.openCamera(CameraActivity.java:919)

What i am doing wrong?

Aucun commentaire:

Enregistrer un commentaire