Android Question Can WebViewExtras2 support a native file upload?

JohnC

Expert
Licensed User
Longtime 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:

https://www.b4x.com/android/forum/threads/upload-files-with-webview.98623/

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:

JohnC

Expert
Licensed User
Longtime 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:

https://www.b4x.com/android/forum/threads/webviewextras.12453/#post-102448

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:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
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.
It will look exactly the same.

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

JohnC

Expert
Licensed User
Longtime 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 (https://www.b4x.com/android/forum/threads/upload-files-with-webview.98623/), 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:

B4X:
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 ;)
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
The answer is given in post #3: https://www.b4x.com/android/forum/threads/upload-files-with-webview.98623/#post-623620
No. You cannot combine both chrome clients.

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):

https://www.b4x.com/android/forum/t...v-2-sample-with-all-events.75171/#post-477863

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:
Upvote 0

hanyelmehy

Active Member
Licensed User
Longtime 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):

https://www.b4x.com/android/forum/t...v-2-sample-with-all-events.75171/#post-477863

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.
did you get any solution ?
 
Upvote 0
Top