2

我已将 ZXing 代码集成到我的应用程序中。我被告知不要将整个库复制并粘贴到我的应用程序中,而是获取我需要的部分。我从捕获活动开始,然后将它的依赖项复制到我的应用程序中。我将意图过滤器从 zxing one 更改为我的意图过滤器。哦,我不得不更改 capture.xml 中的包名称。

它似乎工作正常,当我的活动调用 startActivityForResult() 扫描仪启动。问题是当我扫描二维码时,扫描结果不会传播回我的呼叫活动,而是询问如何完成操作,例如短信、电子邮件等。

如何让扫描结果返回到我的活动的 onActivityResult?

在此先感谢马特

 Button signin = (Button)findViewById(R.id.buttonsignin);

        alpha = new AlphaAnimation(0.3F, 0.8F); //Set opacity - Range 0.0 to 1.0
        alpha.setDuration(0); // Set animation duration
        alpha.setFillAfter(true); // Maintaining the effect to the button
        signin.startAnimation(alpha);
        signin.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Log.e(TAG, "onclicked sign in");

                Intent intent = new Intent(
                        "com.carefreegroup.SCAN");
                intent.putExtra("SCAN_MODE", "QR_CODE_MODE");

                startActivityForResult(intent, 0);

            }
        });

.

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        Log.e(TAG, "in onActivityResult");
        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                Log.e(TAG, "result ok");

//              
                ///////////////////////////////



                tagScanTime  = new DateTime();

                DateTimeFormatter df = DateTimeFormat.forPattern("dd/MMM/yy h:mmaa");
                String formattedScanTime = df.print(tagScanTime);
                Log.e(TAG, "formatted tag scan time = " + formattedScanTime);



                 contents = intent.getStringExtra("SCAN_RESULT");
//              Toast.makeText(this, "scanner has found " + contents,
//                      Toast.LENGTH_LONG).show();

                 //get info from tag that has been just scanned
                    String[] splitPayload = contents.split(",");

                    tagType = splitPayload[0];
                    tagCompany = splitPayload[1];
                    tagCompany = nfcscannerapplication.getCompId();
                    //tagPerson = splitPayload[2];
                    cursor = nfcscannerapplication.loginValidate.queryAllFromCarer();
...............
..............
..............

.

<activity android:name=".CaptureActivity" >
            <intent-filter>
                <action android:name="com.carefreegroup.SCAN" />

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

0 回答 0