Close Activity after result

Asked

Viewed 315 times

1

I’m trying to implement a tutorial using Zxing to read Qrcode. In the tutorial who was accompanying him uses the Eclipse and places the libs of Zxing all importing "by hand". I am using Android Studio and used the Gradle to generate the dependencies.

But there comes a time when he edits a class of lib of Zxing because it is necessary after taking the photo of Qrcode that returns to ActivityMain to show the result, otherwise it gets stopped in the Activity camera.

My doubts are:

  • I can’t find where the Gradle lower the dependencies for me to edit it.
  • Is there any other way to make sure that after reading the Qrcode to Activity close?

Here is the code as implemented.

1 answer

1

You don’t necessarily need to change the class CaptureActivity, you can create a Activity your extending this, and as the change is only in this method, just overwrite it and implement as the tutorial says.

Let’s assume you create this new Activity thus:

public class ScanActivity extends CaptureActivity {
    @Override
    public void handleDecode(Result rawResult, Bitmap barcode, float scaleFactor) {
        Intent it = getIntent();
        it.putExtra("SCAN_RESULT", rawResult.getText());
        it.putExtra("SCAN_FORMAT", rawResult.getBarcodeFormat());
        setResult(Activity.RESULT_OK, it);
        finish();
    }
}

So, enough instead of calling CaptureActivity directly, call this your new ScanActivity:

Intent it = new Intent(MainActivity.this, ScanActivity.class);

Remembering that you should also change the Manifest, as indicated in the tutorial.

  • quando eu tentei estender a classe CaptureActivity da um erro falando que eu não posso usa-la como herança:"cannot inherit from final 'com.google.zxing.client.android.CaptureActivity'",pastebin do codigo:http://pastebin.com/SqEpQFNH,você sabe o que pode ser?

  • I had not noticed, it seems that there were changes in this library and now this class is a final and can no longer be extended. The alternatives then remain in other solutions such as this or even you manually import this library without the Gradle.

  • do you know any app that I can call an Internet with it and it read and give me back the result? ,because with Zxing is not rolling :/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.