I have a problem with webview embedded in my application (Android 4.4.4+). There is a button “Download Image” on the page that I control with openFileChooser.
On some devices, when I click the “Download Image” button in a web browser, the camera application launches and my application is destroyed. After the image has been restored, I restore the state of the web view (saved to onSaveInstanceState) and called onActivityResult(). The problem is that the variable mUploadMessagecontaining ValueCallBackis null, so I cannot call ValueCallBack.onReceiveValue()to provide the image URI to the webview.
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
mUploadMessage = uploadMsg;
fileChooserManagement(FILECHOOSER_RESULTCODE);
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
webview.saveState(outState);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (savedInstanceState != null) {
webview.restoreState(savedInstanceState);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == FILECHOOSER_RESULTCODE) {
if (this.mUploadMessage == null) {
Log.i("myApp", "onActivityResult mUploadMessage is null");
return;
}
mUploadMessage.onReceiveValue(processPicture(resultCode, data));
mUploadMessage = null;
}
}
, " , - . onRestoreInstanceState() . ?" .
!