在android上,detector.isOperational()总是假的 [英] detector.isOperational() always false on android

查看:338
本文介绍了在android上,detector.isOperational()总是假的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用新的Google Play服务条形码检测器,对于这个问题我正在遵循本教程: https://search-codelabs.appspot.com/codelabs/bar-codes

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

但是当我在我的真实设备(华硕Nexus 7)上运行该应用程序时,该应用程序的文本视图始终显示无法设置探测器,我不知道如何制作它工作>< ...

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);
}
}


推荐答案

我现在有这个问题。您无法更新Google Play服务。在我使用与教程相同的内容后,它可以工作。

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

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

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

这篇关于在android上,detector.isOperational()总是假的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆