java - detector.isOperational() 在 android 上总是 false

标签 java android barcode

我正在使用新的 google plays 服务:条形码检测器,对于这个海豚,我正在学习这个教程:https://search-codelabs.appspot.com/codelabs/bar-codes

但是当我在我的真实设备(Asus Nexus 7)上运行应用程序时,应用程序的 TextView 总是显示“无法设置检测器”,我不知道如何让它工作 > < ...

这里是一些用于快速调试的代码:

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 服务完成的。这是链接:

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

这是摘录:

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.

关于java - detector.isOperational() 在 android 上总是 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32202685/

相关文章:

android - java.lang.NoClassDefFoundError : com. 谷歌.android.gms.common.AccountPicker

android - Activity 中的 BroadcastReceiver

delphi - 请帮助如何将C代码转换为Delphi代码(qsBarcode)

java - 转换日期中特定范围的随机数

java - 是否有用于管理 UNIX ACL 的 Java 接口(interface)

java - While 循环在音频播放器中不起作用

barcode - 将 EAN-8 转换为 EAN-13

java - PayPal PaymentDetails getReceiverList() 为空。为什么?

android - Cypher SharedPreferences JSON 对象

React-native-camera 限制条码扫描区域