Zxing QR Reader不再重点关注

时间:2013-05-10 08:26:36

标签: android qr-code

我使用 zxing库为QR阅读器制作了一个应用程序。

我的问题是当SCAN活动开始时,它会关注取景器中的任何内容,然后如果置于其他任何位置,则拒绝再次关注焦点。请帮忙。

主要班级

public class main extends Activity {
    final Context context = this;
    final Activity activity = this;
    Button scanButton;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        scanButton = (Button) findViewById(R.id.button1);
        scanButton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub

                    Intent intent = new Intent(
                                               "com.google.zxing.client.android.SCAN");
                    intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
                    startActivityForResult(intent, 0);
                    // IntentIntegrator integrator = new IntentIntegrator(activity);
                    // integrator.initiateScan();

                }
            });

    }

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        // IntentResult scanResult =
        // IntentIntegrator.parseActivityResult(requestCode, resultCode,
        // intent);
        // if (scanResult != null) { // handle scan result
        // String contents=scanResult.getContents();
        // }
        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                String contents = intent.getStringExtra("SCAN_RESULT");
                String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
                // Handle successful scan
                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                                                                                 context);

                alertDialogBuilder.setTitle("Scan Result");

                // set dialog message
                alertDialogBuilder.setMessage(contents).setPositiveButton("Ok",
                                                                          new DialogInterface.OnClickListener() {
                                                                              public void onClick(DialogInterface dialog, int id) {
                                                                                  // if this button is clicked,
                                                                                  // close
                                                                                  // current activity
                                                                                  dialog.cancel();
                                                                              }
                                                                          });
                // create alert dialog
                AlertDialog alertDialog = alertDialogBuilder.create();
                // show it
                alertDialog.show();

            } else if (resultCode == RESULT_CANCELED) {
                // Handle cancel
            }
        }
    }

}

的manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
            package="com.scanner.demo" android:versionCode="1" android:versionName="1.0">

    <uses-permission android:name="android.permission.CAMERA" />
    <application android:icon="@drawable/launch_icon"
                   android:label="@string/app_name">
        <activity android:name=".main" android:label="@string/app_name"
                    android:configChanges="orientation|keyboardHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.google.zxing.client.android.CaptureActivity"
                    android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden"
                    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
                    android:windowSoftInputMode="stateAlwaysHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <intent-filter>
                <action android:name="com.google.zxing.client.android.SCAN" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>
</manifest>

我需要相机在一段时间后再次聚焦。我在哪里进行必要的更改?

0 个答案:

没有答案