Workaround for downloading files on Android 4.4 using reflection

From Android 4.1 to Android 4.3, you can subclass WebChromeClienton Android and implement the following method (hidden rather than @Override):

public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { ... }

You will open the file collector in this method, and when your Activitygets the result in onActivityResult(...), just call the only method that is available in the instance ValueCallback<Uri>with the file URI. What is it.

Unfortunately, this method has been removed from the API in Android 4.4 and is no longer called.

Is there a way you can get around this, for example. with reflection?

I mean, you can set a listener onclick="..."on an element <input type="file">in HTML that will still be called.

After intercepting the callback onclick="..."in Java (possibly via addJavascriptInterface(...)), you can open the file collector as usual. But the problem is that there is no instance ValueCallback<Uri>available to send your result (the file that was selected).

value="..." <input type="file">Manual installation in HTML is also not possible because it is read-only. But the implementation itself WebView, of course, can spell the meaning. Can you use reflection to set the value there or find another workaround?

I am looking for a more convenient and convenient solution than detecting a click <input type="file">(for example, through its onclick="..."listener) and performing file selection and downloading the file manually from Java. Enabling file uploads in WebView, how they should work, would, of course, be cleaner.

+4
1

, Javascript. Webview.


. -. ChromeView. : https://crosswalk-project.org/documentation/embedding_crosswalk.html

: https://crosswalk-project.org/

Chromium Webview
ChromeView. , API, -, . , Webview .

: https://github.com/mogoweb/chromium_webview

GeckoView
Mozilla. , . Mozilla : " - ",

: https://wiki.mozilla.org/Mobile/GeckoView

Javascript (, ), :

Kitkat Webview
javascript, - KitKat. , .

: https://github.com/henrychuangtw/Kitkat-WebView

+6

All Articles