【问题标题】:BarCodeEye QR Cocde Scanner implementation in my applicationBarCode e QR Code Scanner 在我的应用程序中的实现
【发布时间】:2014-04-10 08:51:12
【问题描述】:

我正在尝试将二维码扫描仪集成到我的 android 应用程序中,我正在使用 zxing 库 BarcodeEye。

我已经实现了下面的一段代码

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}

谁能帮我解决我哪里出错了

感谢和问候。 纳根德拉

【问题讨论】:

  • 分享你的代码一定会有帮助。
  • 您是如何将 zxing 添加到您的 Glass 应用程序的?
  • 我使用了 BarCodeEye,它是 ZXING for Glass 的端口

标签: barcode zxing google-glass


【解决方案1】:

您需要在 AndroidManifest.xml 中注册 CaptureActivity 活动

<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>

【讨论】:

    【解决方案2】:

    这是我使用 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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-09
      • 2016-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多