简体   繁体   中英

Android barcode scanner app ,after pressing the scan button the camera does not open

I am using android studio with intentintegrator and intentResult classes for a barcode scanner app. The scan button does not open up the camera to scan. I have checked the code with all the tutorials and it is correct with no errors on build. I have all the permissions and libraries imported. All suggestions welcome thanks

I had your same issue and took me alot of time to find the reason...it's due to the permission....check your camera code you will find a code some thing like this:

 `if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (checkPermission()) {
            Toast.makeText(this, "Premission granted", Toast.LENGTH_LONG).show();
        } else {
            requestPermissions();
        }
    }`

this means that the permission will be send and granted to the devices which have only andriod version "M" or above...you can rewrite the if condition to send the permission to lower versions...for me I made it start from "JELLY_BEAN_MR1" and the if condition is like this :

 `  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        if (checkPermission()) {
            Toast.makeText(this, "Premission granted", Toast.LENGTH_LONG).show();
        } else {
            requestPermissions();
        }
    }`

and make sure to rewrite every if condition to the same thing.

Hope this will help you :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM