Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get resultCode, is it possible? #694

Closed
jfoucry opened this issue Jan 31, 2022 · 2 comments
Closed

Get resultCode, is it possible? #694

jfoucry opened this issue Jan 31, 2022 · 2 comments

Comments

@jfoucry
Copy link

jfoucry commented Jan 31, 2022

Using a customScannerView:

Which library version are you using?

4.3.0.

Which phone/tablet are you using, and which Android version does it run?
OnePlus 5T/FP3

Does the same happen on other devices or an emulator?
Does not use emulator my computer is too weak for that.

I have a customScanncerActivity, with a custom layout.

  • Three buttons:
    • torch on/off → work well;
    • cancel → work weel;
    • use keyboard → use a returnCode in order to launch an other activity.

How can I get this returnCode?

In custom_barcode_scanner.xml

<ImageButton
        android:id="@+id/keyboard_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:backgroundTint="@android:color/transparent"
        android:contentDescription="@string/button_keyboard"
        android:onClick="onKeyboard"
        android:src="@drawable/ic_keyboard_black_24dp" />

In customScannerActivity.java

    public void onKeyboard(View view) {
        setResult(3);
        finish();
    }

So in ActivityResultLauncher<ScanOptions> barcodeLauncher = registerForActivityResult(new ScanContract(),..
result.getContent() is null, is there a way to get the resultCode?

@rkistner
Copy link
Member

You'll need to implement a custom ActivityResultContract. See the default implementation here:

public ScanIntentResult parseResult(int resultCode, @Nullable Intent intent) {
return ScanIntentResult.parseActivityResult(resultCode, intent);
}

See the Android documentation for details:
https://developer.android.com/training/basics/intents/result#custom

@jfoucry
Copy link
Author

jfoucry commented Feb 5, 2022

Ok thanks, That exactly what I fear about. I close the issue thanks for your time and your advice.

@jfoucry jfoucry closed this as completed Feb 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants