Android Question Can WebViewExtras2 support a native file upload?

Discussion in 'Android Questions' started by JohnC, Mar 2, 2019.

  1. JohnC

    JohnC Well-Known Member Licensed User

    I was wondering if it would it be possible to add support for native file uploading in Webviewestras2?

    Erel, posted code that can do this:

    But it replaces the webchromeclient, making it incompatible with webviewextras. Since my app uses many features of WVE, I need to be able to continue using it.

    My app displays a third party website, so I have no control over the files/pages on the website, so I can't use okHTTPutils2 to do the file uploading because I cant place a custom "upload receive" webpage on that thirdparty site to receive the file.

    I need to be able to upload a file from my app to a thirdparty site that has a webpage with a typical "Browse" button on it. And I want to have the thirdparty site think that the file my app uploaded was uploaded by a normal user clicking on the "Browse" button on the webpage using a normal browser. This is why I like Erels code because it works with the normal "Browse" button as found on many websites and intercepts the "browse" event, which then allows me to do some custom file selection/generation, then my app could upload the file to the thirdparty webpage without any issues - And the third party webpage will handle the upload just like it would for any other file uploaded by a user using a normal browser.

    So, is there a way to use WVE2 to upload a file to a thirdparty website like Erel's example does?
    Last edited: Mar 3, 2019
  2. Erel

    Erel Administrator Staff Member Licensed User

    Have you tried to use WebViewExtras2 without calling wve.SetWebViewChromeClient?
  3. JohnC

    JohnC Well-Known Member Licensed User

    No, but even if it worked without setting the chomeclient, that wouldn't help because certain features of WVE need the chromeclient, such as the location permission event:

    Also, since my app is displaying a thirdparty website that contains modern design/CSS, rendering the page using the chromeclient I'm thinking would be more reliable/accurate then using the default browser client.
    Last edited: Mar 3, 2019
  4. Erel

    Erel Administrator Staff Member Licensed User

    It will look exactly the same.

    Change the Java code to:
    #if Java
    import android.webkit.*;
    import android.webkit.WebChromeClient.*;
    public static void SendResult(Uri uri, ValueCallback<Uri[]> filePathCallback) {
       if (uri != null)
           filePathCallback.onReceiveValue(new Uri[] {uri});
    public static class MyChromeClient extends WebChromeClient {
     public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
                FileChooserParams fileChooserParams) {
           processBA.raiseEventFromUI(this, "showfile_chooser", filePathCallback, fileChooserParams);
            return true;
       public void onGeolocationPermissionsShowPrompt(String origin,
                GeolocationPermissions.Callback callback) {
               callback.invoke(origin, true, true);
    #End If
    Location permissions will be accepted automatically.
  5. JohnC

    JohnC Well-Known Member Licensed User

    Hi Erel, I totally understand that you are just trying to help, and I appreciate that very much.

    I also made a post at the end of the thread I mentioned (, but it looks like it was deleted, probably because it was considered a "duplicate" to this post. But I was hoping it would not be considered a duplicate because with that post I was asking if there was a way to make your method compatible with webviewextras2. I then created this thread asking if webviewextras2 can add the file upload ability to it - so I considered them two different questions.

    Anyway, in my post in the other thread (that was deleted), I mentioned that my app also uses other features of WVE such as:

    wve.addJavascriptInterface(wv, "B4A")
    wve.executeJavascript(wv, Javascript)
    But this is just one example of other features of WVE that my app uses.

    So, I greatly appreciate you providing how to add location permissions to your code. However, duplicating each feature of WVE one at a time seems a little inefficient. That's why I made two posts to:

    1) See if you can make your code compatible with WVE (deleted post)
    2) Ask Warwound if he can add the file upload ability to his library.

    This way I will not have to ask you how do recode every feature of WVE ;)
  6. Erel

    Erel Administrator Staff Member Licensed User

  7. JohnC

    JohnC Well-Known Member Licensed User

    I did see that, but I was hoping maybe there was a way to integrate your chromeclient into WVE (instead of combining chromeclients) because I see mention of "DefaultWebChromeClient" in this forum as if it is an object that gets ADDED to WVE (post #2 below):

    And I didn't know if there was maybe a way to ADD your chromeclient object to WVE (via the wve.SetWebChromeClient(x)) instead of ADDing a default chromeclient so maybe it could provide a way to combine both.

    But, I am not an expert at this, so it was just a thought.
    Last edited: Mar 4, 2019
  8. hanyelmehy

    hanyelmehy Active Member Licensed User

    did you get any solution ?
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice