条形码扫描仪意图启动,但无法扫描二维码?

时间:2014-05-24 22:53:17

标签: android-intent zxing

我在玩ZXing。我的Android手机上安装了条形码扫描仪并验证它可以扫描二维码。然后我使用了我在另一篇SO帖子中找到的代码:

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // ALT+ENTER
    Intent intent = new Intent("com.google.zxing.client.android.SCAN");
    intent.putExtra("SCAN_MODE", "PRODUCT_MODE");//for Qr code, its "QR_CODE_MODE" instead of "PRODUCT_MODE"
    intent.putExtra("SAVE_HISTORY", true);//this stops saving ur barcode in barcode scanner app's history
    startActivityForResult(intent, 0);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 0) {
        if (resultCode == RESULT_OK) {
            String contents = data.getStringExtra("SCAN_RESULT"); //this is the result
        } else
        if (resultCode == RESULT_CANCELED) {
            // Handle cancel
            Toast.makeText(this, "Scanning cancelled!", Toast.LENGTH_LONG);
        }
    }
}

意图从我的应用程序启动,但它无法扫描相同的qr代码!我在清单中添加了此权限(忽略了SO可见性标记):

uses-permission android:name="android.permission.CAMERA"

再次运行应用程序,但仍然无法扫描!

1 个答案:

答案 0 :(得分:0)

您的回答在您自己的评论中。您要求它仅扫描产品格式而不扫描QR码。