I am opening the image choose option from the android webview app. The camera clicks event not happening further if I click on the device back button after opening the camera & files selection option. The issue is only in Android 11 and all other versions it's working fine after clicking the device back button.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
writeLog("Web Frame -->" + Thread.currentThread().getStackTrace()[1].
getLineNumber() + " --> Camera onActivityResult Version R and Greater --> requestCode --> " + requestCode);
if (requestCode != INPUT_FILE_REQUEST_CODE || mFilePathCallback == null)
{
writeLog("Web Frame -->" + Thread.currentThread().getStackTrace()[1].
getLineNumber() + " --> Camera onActivityResult requestCode --> NULL ");
super.onActivityResult(requestCode, resultCode, intent);
return;
}
Uri[] results = null;
// Check that the response is a good one
if (resultCode == Activity.RESULT_OK) {
writeLog("Web Frame -->" + Thread.currentThread().getStackTrace()[1].
getLineNumber() + " --> Camera onActivityResult --> RESULT_OK ");
if (intent == null) {
writeLog("Web Frame -->" + Thread.currentThread().getStackTrace()[1].
getLineNumber() + " --> Camera onActivityResult data --> null ");
// If there is not data, then we may have taken a photo
if (mCameraPhotoPath != null) {
writeLog("Web Frame -->" + Thread.currentThread().getStackTrace()[1].
getLineNumber() + " --> Camera onActivityResult mCameraPhotoPath --> not null ");
results = new Uri[]{Uri.parse(mCameraPhotoPath)};
}
} else {
writeLog("Web Frame -->" + Thread.currentThread().getStackTrace()[1].
getLineNumber() + " --> Camera onActivityResult DATA --> NOT null ");
String dataString = intent.getDataString();
writeLog("Web Frame -->" + Thread.currentThread().getStackTrace()[1].
getLineNumber() + " --> Camera onActivityResult DATA --> NOT null dataString "+dataString);
if (dataString != null)
{
results = new Uri[]{Uri.parse(dataString)};
writeLog("Web Frame -->" + Thread.currentThread().getStackTrace()[1].
getLineNumber() + " --> Camera onActivityResult dataString --> NOT null ");
}
else
{
writeLog("Web Frame -->" + Thread.currentThread().getStackTrace()[1].
getLineNumber() + " --> Camera onActivityResult dataString --> NULL ");
results = new Uri[]{pictureUri};
//results= pictureUri.getPath();
}
}
mFilePathCallback.onReceiveValue(results);
mFilePathCallback = null;
}
else if (resultCode == Activity.RESULT_CANCELED) {
//if (requestCode == file_req_code) {
Log.e(TAG, "Image file creation failed");
// return;
// mFilePathCallback.onReceiveValue(null);
if (requestCode == file_req_code) {
if (null == file_data)
return;
Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData();
file_data.onReceiveValue(result);
file_data = null;
}
//}
}
writeLog("Web Frame -->" + Thread.currentThread().getStackTrace()[1].
getLineNumber() + " --> Camera onActivityResult Length --> "+results.length+" result "+results[0].toString());
} else if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
writeLog("Web Screen -->"+ Thread.currentThread().getStackTrace()[1].
getLineNumber()+" Camera onActivityResult--> Inside Version Q or Less");
Uri[] results = null;
//Toast.makeText(getApplicationContext(),"Result.."+intent,Toast.LENGTH_LONG).show();
/*-- if file request cancelled; exited camera. we need to send null value to make future attempts workable --*/
if (resultCode == Activity.RESULT_CANCELED) {
if (requestCode == file_req_code) {
file_path.onReceiveValue(null);
return;
}
}
/*-- continue if response is positive --*/
if (resultCode == Activity.RESULT_OK) {
if (requestCode == file_req_code) {
if (null == file_path) {
return;
}
ClipData clipData;
String stringData;
try {
clipData = intent.getClipData();
stringData = intent.getDataString();
} catch (Exception e) {
clipData = null;
stringData = null;
}
if (clipData == null && stringData == null && cam_file_data != null) {
results = new Uri[]{
Uri.parse(cam_file_data)
};
} else {
if (clipData != null) { // checking if multiple files selected or not
final int numSelectedFiles = clipData.getItemCount();
results = new Uri[numSelectedFiles];
for (int i = 0; i < clipData.getItemCount(); i++) {
results[i] = clipData.getItemAt(i).getUri();
}
} else {
results = new Uri[]{
Uri.parse(stringData)
};
}
}
}
}
file_path.onReceiveValue(results);
file_path = null;
} else {
if (requestCode == file_req_code) {
if (null == file_data)
return;
Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData();
file_data.onReceiveValue(result);
file_data = null;
}
}
}