在android上,detector.isOperational()总是假的

我正在使用新的谷歌播放服务条形码检测器 ,对于这个porposue我正在遵循这个教程: https ://search-codelabs.appspot.com/codelabs/bar-codes

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

这里有一些快速调试的代码:

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 barcodes = detector.detect(frame); Barcode thisCode = barcodes.valueAt(0); txt.setText(thisCode.rawValue); } } 

我现在遇到了这个问题。 您无法更新Google Play服务。 在我使用与教程相同之后,它可以工作。

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

看起来第一次在每台设备上使用条形码检测器,有些下载是由Google Play服务完成的。 链接在这里:

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

这是摘录:

第一次在设备上安装使用条形码和/或面部API的应用程序时,GMS会将库下载到设备以进行条形码和面部检测。 通常,这是在第一次运行应用程序之前由安装程序完成的。

要使用API​​,必须有互联网连接,我已连接到我的ADSL但未解析DNS。 修复该问题使我的应用程序正常工作

有时,应用程序第一次运行时会下载检测器依赖项,而不会在应用程序安装时运行。 我也面临同样的问题,问题是您的网络连接很弱或者您没有足够的存储空间来下载占据总空间的10%,尽管它不占用太多空间但是从Google Play服务下载确实需要很好存储量并且不要忘记清除缓存(简单检查尝试从playstore更新任何应用程序)。 有关更多信息,请参阅此Github线程 。

检查你的存储! 确保它超过10%

这解决了我的问题,我也在这里回答了……

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

你不能忘记这一点:

将其添加到AndroidManifest.xml