Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detector.isOperational() always false on android

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);
}
}
like image 317
Josete Manu Avatar asked Aug 25 '15 11:08

Josete Manu


Video Answer


4 Answers

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.

like image 193
ssasa Avatar answered Oct 08 '22 18:10

ssasa


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+'

like image 42
André Luiz Reis Avatar answered Oct 08 '22 18:10

André Luiz Reis


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.

like image 3
Agmikor Avatar answered Oct 08 '22 18:10

Agmikor


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

like image 1
Josete Manu Avatar answered Oct 08 '22 16:10

Josete Manu