我有以下場景: 我用Gradle的Maven倉庫將ZXing集成到我的Android應用程序。ZXing二維碼掃描器嵌入按下後退按鈕在掃描問題
在我的掃描活動,代碼如下所示:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.scan_layout);
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
integrator.setPrompt(" ");
integrator.setScanningRectangle(700, 700);
integrator.setResultDisplayDuration(0);
integrator.setCameraId(0); // Use a specific camera of the device
integrator.initiateScan();
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
//retrieve scan result
IntentResult scanningResult = null;
scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanningResult != null) {
//we have a result
String scanContent = scanningResult.getContents();
if(isConnected()) {
requestdata("http://rm360project-001-site1.smarterasp.net/api/endpoint", scanContent);
}else {
Toast.makeText(this, "Internet Connection not available", Toast.LENGTH_LONG).show();
}
} else {
Intent getMainScreen = new Intent(ScanScreen.this, MainActivity.class);//pentru test, de sters
startActivity(getMainScreen);
}
}
我希望它的工作方式:
1.如果我掃描QR代碼,調用函數的RequestData
2.如果我在掃描過程中按回去,轉到MainActivity
問題: 即使當我按下我的設備時,函數requestdata被調用,我想因爲scaningResult從不爲null。當按下返回時不應該爲空嗎? 你有什麼想法爲什麼發生這種情況? 謝謝!
這不是行家都有關。 – egore911
我使用Maven Repository來集成掃描器,所以這就是爲什麼我添加了標籤! Gradle構建系統基於Maven –