In Android webview, when file upload option is clicked, onShowFileChooser is called where intent for user to select file to upload from image gallery is invoked. after selecting file, inside onActivityResult it crashes due to following reason
java.lang.IllegalStateException: Duplicate showFileChooser result
at org.chromium.android_webview.AwWebContentsDelegateAdapter$2.onReceiveValue(AwWebContentsDelegateAdapter.java:225)
at org.chromium.android_webview.AwWebContentsDelegateAdapter$2.onReceiveValue(AwWebContentsDelegateAdapter.java:220)
at com.android.webview.chromium.WebViewContentsClientAdapter$4.onReceiveValue(WebViewContentsClientAdapter.java:1063)
at com.android.webview.chromium.WebViewContentsClientAdapter$4.onReceiveValue(WebViewContentsClientAdapter.java:1047)
If you override onShowFileChooser
and plan on calling filePathCallback
to pass results, you must return true from onShowFileChooser
which tells the underlying code not to pass a value to filePathCallback
.
the true is basically saying "I will handle it"
Documentation:
@return true if filePathCallback will be invoked, false to use default handling.
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
mActivity.setValueCallback(filePathCallback);
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
mActivity.startActivityForResult(Intent.createChooser(intent, ""), Final.REQUEST_CODE_ALBUM);
return true;
}
return true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With