Fragment扫描二维码 未触发onActivityResult

fragment可以开启扫描的页面,但是获取返回值的方法未被调用,需要在fragment属于的Activity中重载onActivityResult()方法

1 Activity中


private Fragment fragment;
 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Fragment currentFragment =fragment;
        currentFragment.onActivityResult(requestCode, resultCode, data);
    }

2 在Fragment中

 @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
        if (result != null) {
           //your code
        } else {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }

 

posted @ 2020-09-12 18:48  waityu  阅读(407)  评论(0编辑  收藏  举报