Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to start Zxing on a Fragment?

i have an activity that holds Two Fragments, i want to run ZXING scanner on one of the fragments,

currently i do this on another activity like this >

new IntentIntegrator(this).initiateScan(); // opens up Scan intent > ZXING

how do i do that line but to open up the scan on a fragment ?

Also i get the ZXING results on a reciever like this >

//results when activity enters a callback sent out to another activity
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {

how will i get them on my Fragment that i'm going to run Zxing on ?

THNX

like image 993
Chief Madog Avatar asked Nov 28 '22 14:11

Chief Madog


1 Answers

If you really need to open it in a support fragment you can use:

IntentIntegrator.forSupportFragment(MyFragment.this).initiateScan();

In your Fragment:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
  IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); 
  String barcode = result.getContents();
}

Try it!

like image 108
Daniel Garcia Avatar answered Dec 25 '22 19:12

Daniel Garcia