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