zxing onActivityResult not called in Fragment only in Activity
As Martynnw
pointed out the issue is to call fragment.startActivityForResult
instead of activity.startActivityForResult
. So just use next wrapper:
import android.content.Intent;
import android.support.v4.app.Fragment;
import com.google.zxing.integration.android.IntentIntegrator;
public final class FragmentIntentIntegrator extends IntentIntegrator {
private final Fragment fragment;
public FragmentIntentIntegrator(Fragment fragment) {
super(fragment.getActivity());
this.fragment = fragment;
}
@Override
protected void startActivityForResult(Intent intent, int code) {
fragment.startActivityForResult(intent, code);
}
}
integrator.initiateScan();
Change the above line as
integrator.forSupportFragment(fragment_name.this).initiateScan();