2015-08-25 37 views
3

我使用新的谷歌播放服务条码检测仪,这porposue我下面这个教程:https://search-codelabs.appspot.com/codelabs/bar-codesdetector.isOperational()总是假的Android

但是当我运行应用程序在我的真实设备(Asus 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<Barcode> barcodes = detector.detect(frame); 

    Barcode thisCode = barcodes.valueAt(0); 
    txt.setText(thisCode.rawValue); 
} 
} 
+0

我也面临这个问题 - 的Nexus 4 5.1.1的CyanogenMod 12.1和Google Play服务8.3.0。互联网连接不是一个问题(工作和快速),可用的存储也不是,仍然是运算总是错误的。 –

回答

0

要使用API​​,有必要有互联网连接,我有连接到我的ADSL,但没有解决DNS。解决这个问题使我的应用程序工作

2

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

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

这是摘录:

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

0

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

3

我现在有这个问题。您无法更新Google Play服务。在我使用教程中的教程之后,它就起作用了。

编译 'com.google.android.gms:发挥服务:7.8+'

+1

尝试编译'com.google.android.gms:play-services:7.8.0' - >不带+字符 –