nisrulz / qreader

:white_square_button: [Android Library] Read QR codes using google's mobile vision api, but without the hassle
http://nisrulz.github.io/qreader
Apache License 2.0
371 stars 108 forks source link

Problem access camera in marshmallow #45

Closed kasfulanwar closed 7 years ago

kasfulanwar commented 7 years ago

Hai Mate..

Thanks for your qreader that help me so much in my apps,

my apps works fine in my device with Android 5.0 Lolipop, but I have problem when I test it in Android 6.0 Marshmallow, my apps cannot access the camera, the surface view only display a blank black screen, I already try update my SDK platform to Android 8.0 Oreo and update my JDK to JDK8, but still don't resolve the problem,

I hope you can help me, maybe it's my mistake, I really appreciate your effort and everything you have done,

Best Regards and Thanks a lot..

Attachment : 77c6c6b0-9002-4488-9bf9-b6549bef8f61

nisrulz commented 7 years ago

Have you provided the Runtime Permission? Android M onwards there is runtime permission system, which you need to request while the app is running and the user is supposed to accept that. Only then you would have access to the camera.

kasfulanwar commented 7 years ago

Hai @nisrulz thanks for your advice, I already fix this issue with changing my gradle script

from : defaultConfig { applicationId "###" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" }

to : defaultConfig { applicationId "###" minSdkVersion 14 targetSdkVersion 22 versionCode 1 versionName "1.0" }

I found the solution from a phonegap forum :D , So thanks a lot..

nisrulz commented 7 years ago

@kasfulanwar the fix you have put in is basically not targeting Android M. I believe if you would like to target higher android api, you should look into runtime permissions and that allows you to push your app to the latest android api i.e API 26 which is Android Oreo.

If this works, then good. But in future, if you would want to target API 23+, try out the fix I have suggested.

MrSilverstein commented 5 years ago

Same issue here for Android M devices with qreader version 2.1.2: Right after granting the CAMERA permission with ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.CAMERA), 100), I have to restart the very same Activity (including SurfaceView) again and finish old one to avoid that black screen on SurfaceView: startActivity(Intent(this@QrActivity, QrActivity::class.java)) finish() It would be more elegant if I could avoid calling same Acvtivity again..

nisrulz commented 5 years ago

@murathada that is a limitation on the library and since it has not been updated for some time, this is how it works.

Although I agree it is not elegant and I do want to address this.

MrSilverstein commented 5 years ago

@nisrulz Thanx for answer. Crossing the thumbs fot that library ;)