Okay, found a way to make it work. It's a bit unrefined to be honest but it works and updates real time. The basic concept is to have a multiScan requestCode that is incremented every time that it gives a result as handled in onActivityResult method. Then there's an if statement that checks if the multiScan requestCode has reached the maximum number of iterations desired.
So here are the global variables:
int multiScan = 1;
int multiScanBase = 1;
long start, end, time;
And then the multiScanButton
would look something like:
//Multi Scan Button
public Button.OnClickListener onMultiScan = new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
start = System.nanoTime();
startActivityForResult(intent, multiScan);
}
};
Then the onActivityResult
method would look something like this:
//multiple scan
if (requestCode < multiScanBase + 5 ) {
end = System.nanoTime();
time = (end - start) / 1000000;
System.out.println("Request Code = " + multiScan);
System.out.println("Time" + " " + /*i + +*/ time);
if (resultCode == RESULT_OK) {
String content = data.getStringExtra("SCAN_RESULT");
//codes = codes + contents + " ";
inputs[counter] = content;
counter += 1;
if(counter == 5){
//output();
verify();
}
}
else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
//This is the part where I check for the requestCode
//In this example, I wanted to iterate the activity 5 times
//So if the request code is still less than the base + number of iterations
//Increment the multiScan requestCode and run the method again
//In this way, the time for each scan is given in real time
if(requestCode < multiScanBase + 5){
multiScan += 1;
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, multiScan);
}
}
So there. The code works for me and updates are given in real time. Thanks for the ideas on how to do this.
Merry Christmas everyone.