Android web browsing, file downloads, crashes when setting the result to onActivityResult

In the Android web browser, when you click the download file button, onShowFileChooser is called, where the user's intention to select the file to download from the image gallery is called. after selecting a file, inside onActivityResult it crashes due to the 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)
+4
source share
4 answers
@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

+5
source

If you override onShowFileChooserand plan to call filePathCallbackto pass the results, you must return true from onShowFileChooser, which tells the base code not to pass the value filePathCallback.

: " "

: @return true if filePathCallback will be invoked, false to use default handling.

+1

I think you need to implement webview and extend the webview client interface to handle file uploads in an Android application. You can read this article to help you understand how to implement the webview client class and webchrome client.

0
source

This may be due to the fact that you will take data in uri and then create a new uri array object. In C #, I did below to solve the problem: code that was a double givinf error:

  Android.Net.Uri result = data == null || resultCode != Result.Ok ? null :  data.Data ;
var a = new Android.Net.Uri[] { result };

Below code solved the problem:

Android.Net.Uri[] result = data == null || resultCode != Result.Ok ? null : new Android.Net.Uri[] { data.Data };

0
source

All Articles