how to start Zxing on a Fragment?

后端 未结 5 663
无人共我
无人共我 2021-02-06 15:30

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 >

         


        
5条回答
  •  长情又很酷
    2021-02-06 16:33

    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!

提交回复
热议问题