6

I'm using the new google plays service: Barcode detector, for this porposue I'm following this tutorial : https://search-codelabs.appspot.com/codelabs/bar-codes

But when I run the application on my real device(Asus Nexus 7), the text view of the app always is showing me "Couldn't set up the detector" and i don't know how to make it work >< ...

Here some code for fast debugging:

public class DecoderBar extends Activity implements View.OnClickListener{

private TextView  txt;
private ImageView img;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_decoder);

    Button b = (Button) findViewById(R.id.button);
    txt = (TextView) findViewById(R.id.txtContent);
    img = (ImageView) findViewById(R.id.imgview);

    b.setOnClickListener(this);
}

// [...]

@Override
public void onClick(View v) {

    Bitmap myBitmap = BitmapFactory.decodeResource(getApplicationContext().getResources(),R.drawable.popi);
    img.setImageBitmap(myBitmap);

    BarcodeDetector detector = new BarcodeDetector.Builder(getApplicationContext())
            .setBarcodeFormats(Barcode.DATA_MATRIX | Barcode.QR_CODE)
            .build();

    if(!detector.isOperational()){
        // Always show this message, so, never is operational!
        txt.setText("Could not set up the detector!");
        return;
    }

    Frame frame = new Frame.Builder().setBitmap(myBitmap).build();
    SparseArray<Barcode> barcodes = detector.detect(frame);

    Barcode thisCode = barcodes.valueAt(0);
    txt.setText(thisCode.rawValue);
}
}
Josete Manu
  • 187
  • 2
  • 16
  • I have also faced this issue - Nexus 4 with 5.1.1 CyanogenMod 12.1, and Google Play Services 8.3.0. Internet connection wasn't a problem (working and fast), available storage as well not and still got isOperational always false. – Michał Tajchert Nov 10 '15 at 20:18

7 Answers7

5

It looks like the first time barcode detector is used on each device, some download is done by Google Play Services. Here is the link:

https://developers.google.com/vision/multi-tracker-tutorial

And this is the excerpt:

The first time that an app using barcode and/or face APIs is installed on a device, GMS will download a libraries to the device in order to do barcode and face detection. Usually this is done by the installer before the app is run for the first time.

ssasa
  • 1,616
  • 1
  • 18
  • 30
4

I had this problem now. You can't update the Google Play Services. After I used the same as on the tutorial it works.

compile 'com.google.android.gms:play-services:7.8+'

André Luiz Reis
  • 2,273
  • 21
  • 14
3

Here is what was my case. I was using BarcodeDetector for decoding QR codes from imported images. On 4 my testing devices it was working fine. On one was not reading anything from bitmap. I thought this might be incompatibility with android 5.0 but this was not the case. After hours of investigation I finally noticed that detector.isOperational(); returns false. The reason was:

The first time that an app using barcode and/or face APIs is installed on a device, GMS will download a libraries to the device in order to do barcode and face detection. Usually this is done by the installer before the app is run for the first time.

I had wi-fi off on that testing device. After turning it on and relaunching app, detector became operational and started decoding bitmaps.

Agmikor
  • 31
  • 6
1

To use the API, it's necessary to have internet connection, I had connection to my ADSL but not resolved DNS. Fixing that problem make my app works

Josete Manu
  • 187
  • 2
  • 16
1

Sometimes detector dependencies are downloaded when the app runs for the first time and not when the app installs. I too faced the same issue, the problem is either your network connection is weak or you don't have enough storage for download say 10% of the total space though it does not take that much space but downloads from Google Play Services does require good amount of storage and don't forget to clear cache(Simple check try to update any application from playstore). Refer this Github thread for more information.

Namrata Bagerwal
  • 1,202
  • 13
  • 27
0

Check your storage! make sure it is over 10%

That fixed my problem, and I answered it here too...

https://stackoverflow.com/a/43229272/6914806

Community
  • 1
  • 1
Roshna Omer
  • 687
  • 1
  • 11
  • 20
-1

you must not forget this:

add this to your AndroidManifest.xml

<application
   android:allowBackup="true"
   android:icon="@mipmap/ic_launcher"
   android:label="@string/app_name"
   android:roundIcon="@mipmap/ic_launcher_round"
   android:supportsRtl="true"
   android:theme="@style/AppTheme">


<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />
<meta-data
    android:name="com.google.android.gms.vision.DEPENDENCIES"
    android:value="ocr"/>
Avnesh Shakya
  • 3,828
  • 2
  • 23
  • 31