2011-03-31 3 views
2

현재 내 앱에서 Zxing 라이브러리를 사용하고 있습니다. 예를 들어 책의 바코드를 스캔 한 후에 스캔 결과에서 이미지, 설명 등을 얻는 방법은 무엇입니까? 당신의 도움이스캔 결과를 얻으시겠습니까?

+0

여기 내 대답을 확인하시기 바랍니다가,이 도움말을 희망 http://stackoverflow.com/a/30627814/2904625 – user2904625

답변

1

당신은 안드로이드 ZXing의 응용 프로그램이 무엇을하는지 확인할 수 있습니다에 대한

   @Override 
     public void onActivityResult(int requestCode, int resultCode, Intent intent) { 
      switch(requestCode) { 
      case IntentIntegrator.REQUEST_CODE: 
       if (resultCode == RESULT_OK) { 
        IntentResult scanResult = 
         IntentIntegrator.parseActivityResult(requestCode, resultCode, intent); 
       } else if (resultCode == RESULT_CANCELED) { 
       showDialog("failed", "You messed up"); 
       } 
      } 
     } 

감사합니다. Android 클라이언트의 소스는 ZXing Android client source code입니다. ISBN 번호의 경우, 그 처리에 대한 소스 코드는 다음과 같습니다 Android ZXing app's ISBN Result Handler code

제품 및 책 검색의 경우, 안드로이드 코드 ResultHandler.java에서 두 함수를 호출

// Uses the mobile-specific version of Product Search, which is formatted for small screens. 
final void openProductSearch(String upc) { 
    Uri uri = Uri.parse("http://www.google." + LocaleManager.getProductSearchCountryTLD() + 
     "/m/products?q=" + upc + "&source=zxing"); 
    launchIntent(new Intent(Intent.ACTION_VIEW, uri)); 
} 

final void openBookSearch(String isbn) { 
    Uri uri = Uri.parse("http://books.google." + LocaleManager.getBookSearchCountryTLD() + 
     "/books?vid=isbn" + isbn); 
    launchIntent(new Intent(Intent.ACTION_VIEW, uri)); 
} 
4

Zxing 바코드/QR 코드의 다양한 스캔, 그래서 당신이해야 할 첫 번째 일은 그 경우 제품 UPC 또는 QR 코드를 알아낼 수 있습니다 :

UPC 코드를 특정 제품 메타 데이터를 반환합니다 가능한 웹 서비스의 번호가 있습니다
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     if (data != null) { 
      String response = data.getAction(); 

      if(Pattern.matches("[0-9]{1,13}", response)) { 
       // response is a UPC code, fetch product meta data 
       // using Google Products API, Best Buy Remix, etc.   
      } else { 
       // QR code - phone #, url, location, email, etc. 
       Intent intent = new Intent(Intent.ACTION_VIEW); 
       intent.setData(Uri.parse(response)); 
       startActivity(intent); 
      } 
     } 
    } 

. 상당히 포괄적 인 것은 Google의 Search API for Shopping입니다. 예를 들어,이처럼 보이는 URL과 UPC = 037988482481로 제품의 JSON 표현을 얻을 수 있습니다 :

https://www.googleapis.com/shopping/search/v1/public/products?country=US&key=your_key_here&restrictBy=gtin:037988482481

당신은 구글 API와 함께 "your_key_here"를 교체해야합니다 키.

Best Buy는 UPC 코드로 검색 할 수있는 모든 제품에 대해 RESTful products API을 제공합니다.

UPC를 사용하면 AsyncTask를 사용하여 제품 메타 데이터를 가져오고 싶을 것입니다.

-1

RuntimeException없이 뒤로 누를 수 있도록하려면 try catch 문으로 if 문을 감싸고 싶을뿐입니다. 그래서 :

try{ 
/// get scanned code here 
} catch(RuntimeException e) { 
e.getStackTrace(); 
{ 

당신이 그것 없이는 피할 수없는 충돌을 도운 희망.

2

'IntentResult'또는 'IntentIntegrator'가 필요하지 않습니다.
당신은이 작업을 수행 할 수 있습니다 다음

Intent intent = new Intent("com.google.zxing.client.android.SCAN"); 
intent.putExtra("SCAN_MODE", "PRODUCT_MODE"); 
startActivityForResult(intent, 0); 

onActivityResult에 : 당신이 바코드를 스캔이와

if (requestCode == 0) { 
    if ((resultCode == RESULT_CANCELED) || (resultCode == -1000)) { 
    Toast.makeText(WebViewActivity.this, "Nothing captured", 
        Toast.LENGTH_SHORT).show(); 
} else { 
    String capturedQrValue = data.getStringExtra("barcode_data"); 
} 
} 

을 지금 찾는 구글의 API를 사용하는 다른 라이브러리는 Zxing 코드가 ISBN. 클래스 Intents.java에는 의도가 필요한 보조 정보가 있으며 그 결과 인 ISBNResultHandler 클래스가 표시됩니다. 앞으로 도움이되기를 바랍니다. 당신의 onActivityResult에서

0

당신은 result.getContents()을 호출되지 않은 코드를

IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); 
    if(result != null) { 
     if(result.getContents() == null) { 
      Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show(); 
     } else { 
      String qrCode=result.getContents(); 
     } 
    } else { 
     // This is important, otherwise the result will not be passed to the fragment 
     super.onActivityResult(requestCode, resultCode, data); 
    } 

을 다음과 같이 수행합니다.