I'm using zxing android to san QR code.
To initialise scan object in HomeFragment in onCreateView:
//intializing scan object
//qrScan = new IntentIntegrator(this.getActivity()); // this is for activity
qrScan = IntentIntegrator.forSupportFragment(this); // this is for fragment
To get the scanner result:
// Get the results:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(result != null) {
if(result.getContents() == null) {
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
However, I'm getting:
error: onActivityResult(int,int,Intent) in HomeFragment cannot override onActivityResult(int,int,Intent) in Fragment attempting to assign weaker access privileges; was public
After changing it from "protected" to public, onActivityResult was not called in HomeFragment.