您好我的QR码阅读器使用zxing。我的屏幕上有两个按钮,每个按钮都会打开QR码扫描仪。然后我有一个onActivityResult方法,一旦扫描程序读取代码就会调用它。
我怎么能看到哪个按钮被称为QR扫描仪INSIDE onActivityResult
这是我的代码:
public void cardOneClicked(View view){
Toast.makeText(getApplicationContext(),
"Card one Clicked with ID: " + Integer.toString(cardOneID), Toast.LENGTH_SHORT).show();
IntentIntegrator integrator = new IntentIntegrator(activity);
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
integrator.setPrompt("Scan 1");
integrator.setCameraId(0);
integrator.setBeepEnabled(true);
integrator.setBarcodeImageEnabled(true);
integrator.setOrientationLocked(false);
integrator.initiateScan();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (result != null){
if(result.getContents() == null){
Toast.makeText(this, "You Cancelled Scan", Toast.LENGTH_SHORT).show();
}
else{
result.getOrientation();
Toast.makeText(this, result.getContents(), Toast.LENGTH_SHORT).show();
}
}
else{
super.onActivityResult(requestCode, resultCode, data);
}
}
答案 0 :(得分:1)
使用变量存储您的按钮ID:)
public int buttonPressed; // ADD A VARIABLE TO STORE VALUE
public void cardOneClicked(View view){
Toast.makeText(getApplicationContext(),
"Card one Clicked with ID: " + Integer.toString(cardOneID), Toast.LENGTH_SHORT).show();
IntentIntegrator integrator = new IntentIntegrator(activity);
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
integrator.setPrompt("Scan 1");
integrator.setCameraId(0);
integrator.setBeepEnabled(true);
integrator.setBarcodeImageEnabled(true);
integrator.setOrientationLocked(false);
integrator.initiateScan();
buttonPressed = 1; // SET PRESSED BUTTON 1
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d("BUTTON_TEST", "Pressed button ID is " + buttonPressed); // SHOW BUTTON
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (result != null){
if(result.getContents() == null){
Toast.makeText(this, "You Cancelled Scan", Toast.LENGTH_SHORT).show();
}
else{
result.getOrientation();
Toast.makeText(this, result.getContents(), Toast.LENGTH_SHORT).show();
}
}
else{
super.onActivityResult(requestCode, resultCode, data);
}
}