我需要構建一個應用程序來識別QR碼,而不會強制用戶安裝其他應用程序。將來,我還需要在識別代碼之前操作掃描的圖像(由我掃描的代碼將具有反轉的顏色)。將ZXing集成到我的應用程序中
試圖按照提示和教程從這些鏈接:
Integrating the ZXing library directly into my Android application
Embedding ZXing in android app
http://karanbalkar.com/2013/12/tutorial-65-implement-barcode-scanner-using-zxing-in-android/
創造一些基本的代碼並運行該應用程序後,我點擊我的掃描按鈕,並得到一個錯誤No Activity found to handle Intent { act=com.google.zxing.client.android.SCAN (has extras) }
我所做的:
創建新項目
Copy core-3.2.1.ja R鍵庫/
添加調用的意圖和結果處理由我添加
意圖/結果代碼:
private Button scan;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scan= (Button)findViewById(R.id.btnScan);
scan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
MultiFormatWriter writer = new MultiFormatWriter();
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
Log.i("App","Scan unsuccessful");
}
}
}
如何啓動意圖是什麼?我究竟做錯了什麼?
哪裏應該從'IntentIntegrator'類?它在zxing庫嗎? – Val
yes,'import com.google.zxing.integration.android.IntentIntegrator;' –
我編譯了這些庫:'compile'com.journeyapps:zxing-android-embedded:[email protected]' compile'com.google。 zxing:core:3.2.0'' –