gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:20:04 25 4
gpt4 key购买 nike

我正在使用新的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com