Question

i am trying to integrate qr code scanner in my application in android, i am using zxing library BarcodeEye.

i have implemented below piece of code

Intent intent = new Intent("com.github.barcodeeye.scan.CaptureActivity");
        intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
        startActivityForResult(intent, 0);

but i am getting a RuntimeException saying that unable to start activity component : android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.github.barcodeeye.scan}

can any one help me where i am going wrong

Thanks & Regards. Nagendra

Was it helpful?

Solution

You will need to register CaptureActivity Activity in the AndroidManifest.xml

<activity
        android:name="com.github.barcodeeye.scan.CaptureActivity"
        android:clearTaskOnLaunch="true"
        android:configChanges="orientation|keyboardHidden"
        android:screenOrientation="landscape"
        android:stateNotNeeded="true"
        android:theme="@style/CaptureTheme"
        android:windowSoftInputMode="stateAlwaysHidden" >
        <intent-filter>
            <action android:name="com.github.barcodeeye.SCAN" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

OTHER TIPS

Here is how I use BarCodeEye:

private void startScanActivityForResult(Bundle extras)
{
    Intent intentScan = new Intent("com.github.barcodeeye.SCAN");
    intentScan.setPackage("com.github.barcodeeye");
    intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    intentScan.putExtras(extras);
    intentScan.putExtra("SCAN_MODE", "QR_CODE_MODE");
    intentScan.putExtra("RESULT_DISPLAY_DURATION_MS", 1000L);
    intentScan.putExtra("SAVE_HISTORY", false);
    intentScan.putExtra("PROMPT_MESSAGE", "QR scan http://user:pass@server");
    WtcLog.info(TAG, "startScanActivityForResult: startActivityForResult(intentScan=" + intentScan + ", REQUEST_SCAN)");
    startActivityForResult(intentScan, REQUEST_SCAN);
}

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    WtcLog.info(TAG, "onActivityResult data=" + WtcUtilsPlatform.toString(data));

    Bundle extras = null;
    if (data != null)
    {
        extras = data.getExtras();
    }

    switch (requestCode)
    {
        case REQUEST_SCAN:
        {
            WtcLog.info(TAG, "onActivityResult: REQUEST_SCAN");
            if (resultCode == RESULT_OK)
            {
                WtcLog.info(TAG, "onActivityResult: resultCode == RESULT_OK");

                String result = data.getStringExtra("SCAN_RESULT");

                extras = validateScan(result);

                /// your logic here

            }
            else
            {
                WtcLog.warn(TAG, "onActivityResult: resultCode != RESULT_OK; exiting");
                // your logic here
                finish();
            }
            break;
        }
    }
}

private Bundle validateScan(String result)
{
    Bundle extras = new Bundle();

    String[] userpass;

    try
    {
        URI uri = new URI(result);

        String userinfo = uri.getRawUserInfo();
        if (WtcString.isNullOrEmpty(userinfo))
        {
            throw new URISyntaxException(result, "");
        }

        userpass = userinfo.split(":", 2);
        if (userpass.length != 2)
        {
            throw new URISyntaxException(result, "");
        }

        String server = uri.getHost();
        if (WtcString.isNullOrEmpty(server))
        {
            throw new URISyntaxException(result, "");
        }
        extras.putString("server", server);
    }
    catch (URISyntaxException e)
    {
        WtcLog.error(TAG, "validateScan: EXCEPTION", e);
        extras.putString("error", "uri must be in format \"http://username:password@server\"");
        return extras;
    }

    try
    {
        String username = URLDecoder.decode(userpass[0], "UTF-8");
        extras.putString("username", username);

        String password = URLDecoder.decode(userpass[1], "UTF-8");
        extras.putString("password", password);
    }
    catch (UnsupportedEncodingException e)
    {
        WtcLog.error(TAG, "validateScan: EXCEPTION", e);
        extras.putString("error", "username and password must be UTF-8");
        return extras;
    }

    return extras;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top