I have read a lot of similar problems, but none fit my case.
Note: I don't want to use the IntentIntegrator because I don't want to get the google play popup, I already integrated the zxing in my project.
I am in a background process that has been started from my main activity. In another activity (that runs in its own process) I click on a scan button. This button will then trig the scan through the service and the service will then handle the result.
Everything is working fine (I use an AIDL file for inter process comm) but after the scanner has successfully scanned it shows the result in the zxing view (overlays it with my scanned image and info) but it doesn't call onActivityResult. It just stays there.
Here is my code:
First the service starts a "wrapper" activity (because I can't call startActivityForResult
Log.d(TAG, "activate native camera");
Intent barcodeScannerIntent = new Intent("xxx.android.service.DoryBarcodeScanner");
barcodeScannerIntent.addCategory(Intent.CATEGORY_DEFAULT);
barcodeScannerIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
service.getApplicationContext().startActivity(barcodeScannerIntent);
Then in that activity I call the scan:
public void scan() {
Log.i(TAG, "scanning with intent " + SCAN_INTENT);
Intent intentScan = new Intent(SCAN_INTENT);
intentScan.addCategory(Intent.CATEGORY_DEFAULT);
intentScan.putExtra("SCAN_MODE", "ONE_D_MODE");
Log.i(TAG, "start activityForResult with request code " + REQUEST_CODE);
startActivityForResult(intentScan, REQUEST_CODE);
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
Log.i(TAG, "we got a result for activity with code:" + requestCode);
if (requestCode == REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
String result = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
Log.i(TAG, "we got a camera scan: " + result);
// service.handleScan(result);
this.finish();
}
}
}
What can I do so that the scanner exits after a scan?