Zxing扫描仪的Andr​​oid工作室扫描仪、工作室、Zxing、oid

2023-09-07 18:06:44 作者:╰_╯痞子王

我知道如何导入一个最小的Andr​​oid库项目扫描QR code,但之后它扫描QR codeI想有什么样的QR code得到的结果(网址例如),但我真的不知道如何检索结果所以这就是为什么我'问你的帮助。

我试图用这个: https://github.com/ embarkmobile / zxing,Android的最小#定制版图

我用它来启动扫描仪:

  IntentIntegrator积分=新IntentIntegrator(本);
integrator.setCaptureLayout(R.layout.custom_layout);
integrator.initiateScan();
 

在此先感谢 我这样做是对的WebView

  WB =(web视图)findViewById(R.id.webView2);
        wb.loadUrl(重);
 

解决方案

首先,你的活动必须实现的方法 Activity.onActivityResult(INT, INT,意图)键,包括线code是这样的:

 公共无效onActivityResult(INT申请code,INT结果code,意图意图){
   IntentResult scanResult = IntentIntegrator.parseActivityResult(要求code,因此code,意图);
   如果(scanResult!= NULL){
     //处理扫描结果
   }
   //否则继续与其他任何code,你需要在方法
   ...
 }
 

这是在那里你会处理扫描结果。

,只需拨打这个响应用户操作的地方开始扫描过程:

  IntentIntegrator积分=新IntentIntegrator(yourActivity);
 integrator.initiateScan();
 

注意 initiateScan()返回一个AlertDialog这非空,如果是提示用户下载该应用程序。这让调用应用程序潜在管理对话框。具体而言,理想情况下,应用程序关闭对话框,如果它仍然活跃在其 Activity.onPause()方法。

您可以使用的setTitle(字符串)自定义此下载提示对话框的标题(或使用setTitleByID(INT)来设置通过字符串资源ID的称号。)同样,提示信息,并且是/否按钮标签是可以改变的。

最后,您可以使用 addExtra(字符串,对象)来更多的参数添加到用于调用的意图扫描仪。这可以被用于设置不直接由该简化的API暴露的附加选项。

在默认情况下,这将只允许已知能够正确应对这一意图的应用程序这样做。被允许响应该应用程序可以设置setTargetApplications(列表)。例如,设置为 TARGET_BAR code_SCANNER_ONLY 只针对律师code扫描仪应用程序本身。

有关详细信息,请参阅here.

样品code:

 进口android.app.Activity;
进口android.content.Intent;
进口android.os.Bundle;
进口android.util.Log;
进口android.view.View;
进口android.widget.Button;

进口com.google.zxing.integration.android.IntentIntegrator;
进口com.google.zxing.integration.android.IntentResult;

公共类MainActivity延伸活动{

    私人按钮mButton;

    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);

        // 扫描器

        mButton =(按钮)findViewById(R.id.assistant_button);
        mButton.setOnClickListener(新View.OnClickListener(){
            @覆盖
            公共无效的onClick(视图v){
                IntentIntegrator积分=新IntentIntegrator(MainActivity.this);
                integrator.initiateScan();
            }
        });

    }

    公共无效onActivityResult(INT申请code,INT结果code,意图意图){
        IntentResult scanResult = IntentIntegrator.parseActivityResult(要求code,因此code,意图);
        如果(scanResult!= NULL){
            字符串重= scanResult.getContents();
            Log.d(code,再);
        }
        //否则继续与其他任何code,你需要在方法

    }
 }
 

在XML的一个按钮,单击它,扫描一个吧code时,它会返回吧code中的原始内容。

Hi i know how to import a minimal Android library project to scan a qr code but after it scanned the qr code i would like to have a result of what the QR code get (url for example) but i really don't know how to retrieve the results so that's why i'am asking your help.

I'm trying to use this : https://github.com/embarkmobile/zxing-android-minimal#custom-layout

I use this to start the scanner :

IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setCaptureLayout(R.layout.custom_layout);
integrator.initiateScan();

Thanks in advance i did this for the webview

wb  = (WebView)findViewById(R.id.webView2);
        wb.loadUrl(re);

解决方案

First, your Activity must implement the method Activity.onActivityResult(int, int, Intent) and include a line of code like this:

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
   IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
   if (scanResult != null) {
     // handle scan result
   }
   // else continue with any other code you need in the method
   ...
 }

This is where you will handle a scan result.

Second, just call this in response to a user action somewhere to begin the scan process:

IntentIntegrator integrator = new IntentIntegrator(yourActivity);
 integrator.initiateScan();

Note that initiateScan() returns an AlertDialog which is non-null if the user was prompted to download the application. This lets the calling app potentially manage the dialog. In particular, ideally, the app dismisses the dialog if it's still active in its Activity.onPause() method.

You can use setTitle(String) to customize the title of this download prompt dialog (or, use setTitleByID(int) to set the title by string resource ID.) Likewise, the prompt message, and yes/no button labels can be changed.

Finally, you can use addExtra(String, Object) to add more parameters to the Intent used to invoke the scanner. This can be used to set additional options not directly exposed by this simplified API.

By default, this will only allow applications that are known to respond to this intent correctly do so. The apps that are allowed to response can be set with setTargetApplications(List). For example, set to TARGET_BARCODE_SCANNER_ONLY to only target the Barcode Scanner app itself.

For more details, please refer here.

Sample code:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;

public class MainActivity extends Activity {

    private Button mButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Scanner

        mButton = (Button) findViewById(R.id.assistant_button);
        mButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                IntentIntegrator integrator = new IntentIntegrator(MainActivity.this);
                integrator.initiateScan();
            }
        });

    }

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
        if (scanResult != null) {
            String re = scanResult.getContents();
            Log.d("code", re);
        }
        // else continue with any other code you need in the method

    }
 }

One button in your xml, and click it, scan a barcode, the it will return the raw content of barcode.