Android barcode scanner Google Play Service Vision not found

I use the Google play services Visible API to read the barcode. I tried the code from the official CodeLabs example , which does not work on some (not at all) devices. Here is the Logcat post:

I/Vision﹕ Supported ABIS: [armeabi-v7a, armeabi] D/Vision﹕ Library not found: /data/data/com.google.android.gms/files/com.google.android.gms.vision/barcode/libs/armeabi-v7a/libbarhopper.so I/Vision﹕ Requesting barcode detector download. D/AndroidRuntime﹕ Shutting down VM E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: PID: 24921 java.lang.ArrayIndexOutOfBoundsException: length=0; index=0 at android.util.SparseArray.valueAt(SparseArray.java:273) at MainActivity$1.onClick(MainActivity.java:50) at android.view.View.performClick(View.java:4780) at android.view.View$PerformClick.run(View.java:19866) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 

The problem is that the device cannot find the /data/data/com.google.android.gms/files/com.google.android.gms.vision/barcode/libs/armeabi-v7a/libbarhopper.so library, and after I got an exception because of this, because the device does not detect a barcode (the list of barcodes is empty).

Here is the code:

  BarcodeDetector detector = new BarcodeDetector.Builder(getApplicationContext()).build(); Bitmap bitmap = ((BitmapDrawable) mBarcodeImageView.getDrawable()).getBitmap(); Frame frame = new Frame.Builder().setBitmap(bitmap).build(); SparseArray<Barcode> barcodes = detector.detect(frame); Barcode thisCode = barcodes.valueAt(0); TextView txtView = (TextView) findViewById(R.id.txtContent); txtView.setText(thisCode.rawValue); 

Google Play is updated on all devices.

Can anyone help me? How can i fix this?

+5
source share
2 answers

I know it's late, but someone might get an error message and still find this information useful.

Your application crashes due to ArrayIndexOutOfBoundsException . That's why:

SparseArray<Barcode> barcodes = detector.detect(frame); stores all detected data in the barcodes array. When no data is found, it creates an empty array, and you are trying to get the value at index 0 from an empty array.

Before trying to retrieve data, first check the size of the array. Change the code as follows:

 int totalCodes = barcodes.size(); if (totalCodes > 0) { Barcode thisCode = barcodes.valueAt(0); TextView txtView = (TextView) findViewById(R.id.txtContent); txtView.setText(thisCode.rawValue); } 

Or you should use a loop to get all the elements in the barcodes array.

0
source

The detect method returns a SparseArray that contains only keys to the values, you should SparseArray over the results as follows:

 for (int i = 0; i < barcodes.size(); i++) { Barcode barcode = barcodes.get(barcodes.keyAt(i)); String value = barcode.displayValue } 
0
source

All Articles