1

我已经使用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
            }
        }
    }

}

清单.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>

一段时间后我需要相机重新对焦。我在哪里进行必要的更改?

4

0 回答 0