2015-08-25 38 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' - >不帶+字符 –