Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intent.createChooser android QR code reader

I want the user to choose a QR reader from his installed apps. This could be done by using the Intent.createChooser. When a picture is taken with the QR reader, the QR code should be sent back to my application. This is what Ive tried so far:

        Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
            intent.putExtra("SCAN_MODE", "QR_CODE_MODE");

            String title = (String) getResources().getText(R.string.chooser_title);

            Intent chooser = Intent.createChooser(intent, title);

            startActivityForResult(chooser, CUSTOM_REQUEST_QR_SCANNER);

The scanner doens't start correctly, it only shows an sample QR code. I have a feeling the intent.setType("text/plain") might be wrong? What type is a QR reader? Or how do i start a QR reader this way correctly?

I also have an ActivityResult when the QR app is done:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == CUSTOM_REQUEST_QR_SCANNER) {

        Log.d(TAG, "QR activity complete");
                        //Successful scan
                        if (resultCode == RESULT_OK) {
like image 771
rtc11 Avatar asked Nov 01 '25 06:11

rtc11


1 Answers

Replace

intent.setType("text/plain");

with

intent.setType("com.google.zxing.client.android.SCAN");
like image 102
HulkingUnicorn Avatar answered Nov 02 '25 19:11

HulkingUnicorn