如何在不安装实际的zxing应用程序的情况下集成Zxing条形码扫描仪(无法解析符号:.android.CaptureActivity)? [英] How to integrate Zxing Barcode Scanner without installing the actual zxing app (cannot resolve symbol: .android.CaptureActivity)?

查看:292
本文介绍了如何在不安装实际的zxing应用程序的情况下集成Zxing条形码扫描仪(无法解析符号:.android.CaptureActivity)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将zxing扫描仪集成到我的应用程序中,而无需外部应用程序(来自Play商店的zxing扫描仪).这是我的代码

I want to integrate zxing scanner into my app without needed of external application (zxing scanner from play store). This is my code

Button scan = (Button) findViewById(R.id.scan_button);
scan.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
        intent.setPackage("com.mypackage.app");
        intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
        startActivityForResult(intent, SCANNER_REQUEST_CODE);
    }
});

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == SCANNER_REQUEST_CODE) {
        // Handle scan intent
        if (resultCode == Activity.RESULT_OK) {
            // Handle successful scan
            String contents = intent.getStringExtra("SCAN_RESULT");
            String formatName = intent.getStringExtra("SCAN_RESULT_FORMAT");
            byte[] rawBytes = intent.getByteArrayExtra("SCAN_RESULT_BYTES");
            int intentOrientation = intent.getIntExtra("SCAN_RESULT_ORIENTATION", Integer.MIN_VALUE);
            Integer orientation = (intentOrientation == Integer.MIN_VALUE) ? null : intentOrientation;
            String errorCorrectionLevel = intent.getStringExtra("SCAN_RESULT_ERROR_CORRECTION_LEVEL");

        } else if (resultCode == Activity.RESULT_CANCELED) {
            // Handle cancel
        }
    } else {
        // Handle other intents
    }

}

AndroidManifest.xml

<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="com.google.zxing.client.android.SCAN"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>

我的Android Studio说无法解析符号:.android.CaptureActivity,如果我运行此符号,则会发生错误

My Android Studio said that cannot resolve symbol: .android.CaptureActivity and if I run this, error happened

java.lang.ClassNotFoundException:找不到类"com.google.zxing.client.android.CaptureActivity"

java.lang.ClassNotFoundException: Didn't find class "com.google.zxing.client.android.CaptureActivity"

发生了什么事?

推荐答案

我不知道为什么会发生,但是最后我使用了另一个库.我使用 Zxing-android-minimal 此处.现在可以了.

I don't know why it happened, but finally I use another library. I use Zxing-android-minimal and tutorial from here and here. Now it works.

这篇关于如何在不安装实际的zxing应用程序的情况下集成Zxing条形码扫描仪(无法解析符号:.android.CaptureActivity)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆