ZXING Android Embedded 使用 IntentIntegrator [英] ZXING Android Embedded Usage of IntentIntegrator

查看:58
本文介绍了ZXING Android Embedded 使用 IntentIntegrator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Android 开发的新手,仍在尝试掌握一些概念.我发现最好的学习方法是直接进入项目的深度.话虽如此,这是我的问题:

I am new to Android development and still trying to get the grasp of some of the concepts. I find the best way to learn is to jump right into the deep end with a project. With that said, here is my question:

我已将 ZXing Android Embedded 集成到我的应用程序中;但是,我无法理解您使用 IntentIntegrator 的方式.我现在要做的就是在用户点击按钮时将 QR 扫描仪调用到屏幕上.我一直在尝试按照他们的 github 链接 [here][1] 上的说明进行操作,但没有成功.

I have integrated ZXing Android Embedded into my application; however, I am having trouble understanding the way in which you use IntentIntegrator. All I am trying to do at the moment is call the QR scanner to the screen when the user taps a button. I have been trying to follow the instructions on their github link [here][1] but have been unsuccessful.

这是我的函数到目前为止的样子:

Here is what my function looks like so far:

    button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

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

        }

    });

我不断收到错误消息:

错误:(109, 25) 错误:类中的构造函数 IntentIntegratorIntentIntegrator 不能应用于给定的类型;要求:活动发现:意图原因:实际参数意图无法转换为Activity 通过方法调用转换

Error:(109, 25) error: constructor IntentIntegrator in class IntentIntegrator cannot be applied to given types; required: Activity found: Intent reason: actual argument Intent cannot be converted to Activity by method invocation conversion

此外,当我将鼠标放在 Android Studio 中的(this)"上时,它会说:

Also, as I put my mouse over '(this)' in Android Studio, it says:

匿名 android.view.View.onClickListener

anonymous android.view.View.onClickListener

任何帮助将不胜感激,谢谢!如果您需要任何其他信息,请告诉我.

Any help would be greatly appreciated, thanks! If you need any other information, please let me know.

推荐答案

比 ChrisStillwell 更简单的解决方案是让您的活动/片段类实现 OnClickListener,这样您不需要引用变量:

An even easier solution than ChrisStillwell´s would be to make your activity-/fragment-class implement the OnClickListener, this way you do not need the reference variable:

public class SomeFragment extends Fragment implements View.OnClickListener {
    // Rest of your code

    @Override
    public void onClick(View v) {

         if (v.getId == button.getId) {
              IntentIntegrator integrator = new IntentIntegrator(getActivity());
              IntentIntegrator.forFragment(this).initiateScan();
         }
    }
}

如果您正在实现片段类,请注意在创建 IntentIntegrator 时必须调用 getActivity().

If you are implementing a fragment-class, note that you have to call getActivity() when creating the IntentIntegrator.

这篇关于ZXING Android Embedded 使用 IntentIntegrator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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