【问题标题】:Zxing scan clarficationZxing扫描澄清
【发布时间】:2014-05-15 12:04:31
【问题描述】:

我目前正在尝试开发具有 QR 扫描仪功能的应用程序,为此我遵循了一些关于如何实现它的教程,但遇到了一些问题。

尝试制作一个调用扫描功能的按钮,但我遇到了问题。 按钮按钮;

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

public void addListenerOnButton() {

    final Context context = this;


    button = (Button) findViewById(R.id.scan);


    button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if(v.getId()==R.id.scan){
            //scan

                IntentIntegrator integrator = new IntentIntegrator(this);
                integrator.initiateScan();
            }


        }

    });

}

这是我用来调用命令但在线的 IntentIntegrator 积分器 = 新的 IntentIntegrator(this); 它让我回想起一个错误,说构造函数未定义

如果你想看的话,我从here 获得了“IntentIntegrator”和“IntentResult”的源代码。

就我认为我不允许更改任何源代码而言,这只是一个简短的附带问题,这是真的吗?

提前致谢,非常感谢任何帮助。

【问题讨论】:

    标签: android zxing


    【解决方案1】:

    试试这个方法。您需要将当前的Context 传递给Constructor

        IntentIntegrator integrator = new IntentIntegrator(your_activity.this);
    

    【讨论】:

    • 我以为我已经尝试过了,但必须忽略一个拼写错误,谢谢。对第二个问题有任何线索吗?
    • @Sparky 你的问题没有问题。我认为没关系。
    • 我有什么需要说明的地方可以说它已经像版权一样被修改了吗?
    【解决方案2】:

    请传递 MainActivity 上下文而不是 Onclick 上下文。

    1)IntentIntegrator integrator = new IntentIntegrator(MainActivity.this);
    

    2)IntentIntegrator integrator = new IntentIntegrator(context);
    

    【讨论】: