I am using the barcode scanner library of ZXing. It is working fine for all of my testing devices except a Nexus 5 running Android 6. Starting the activity it gives only a black screen and that's all. So I thought, ok, perhaps there are some compatibility problems and I downloaded the official barcode app published by ZXing. But it works fine on that Nexus 5.
So actually I am a bit irritated what I could have done wrong...
In the Android Monitor I get the message:
android an error occurred while connecting to camera 0
I have searched for that status message but haven't found anything useful for me.
Has anyone a suggestion how to solve that problem ? Or a tip how to recognize the reason for the issue?
Android 6 doesn't accept permisions from Manifest file you should ask for permission on runtime. somthing like this :
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
getActivity().checkSelfPermission(Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.CAMERA},
PERMISSIONS_REQUEST_ACCESS_CAMERA);
} else {
mScannerView.startCamera();
}
and then override onRequestPermissionResult :
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == PERMISSIONS_REQUEST_ACCESS_CAMERA) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
mScannerView.startCamera();
}
}
}
hope this helps :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With