Pregunta

I am currently trying to develop an app with a QR scanner feature, in order to do this i have followed a few tutorials on how to implement it im having some problems.

Trying to make a button that will call upon the scanning feature and i am having a problem. Button button;

@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();
            }


        }

    });

}

This is what i am using to call upon the command but on the line IntentIntegrator integrator = new IntentIntegrator(this); Its chucking me back an error saying that the constructor is undefined

I got my source code for the "IntentIntegrator" And "IntentResult" from here if you want to look at and if it.

And just a quick side question as far as i believe i am not allowed to change any of the source code, Is this true?

Thanks in advance, Any help is much appreciated.

¿Fue útil?

Solución

Try this way. You need to pass current Context to the Constructor.

    IntentIntegrator integrator = new IntentIntegrator(your_activity.this);

Otros consejos

please pass MainActivity context instead of Onclick context.

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

or

2)IntentIntegrator integrator = new IntentIntegrator(context);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top