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

 

上一篇:Image_Picker: “PlatformException(already_active, Image picker is already active,null)“


下一篇:Android中代码申请权限(应对android6.0以上)