Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 views
in Technique[技术] by (71.8m points)

HTML file input in android webview (android 4.4, kitkat)

I was using the <input type="file"> on the android webview. I got it working thanks to this thread: File Upload in WebView

But the accepted answer (or any other) no longer works with android 4.4 kitkat webview.

Anybody knows how to fix it?

It doesn't work with target 18 either.

I've looking some android 4.4 source code and it seems that the WebChromeClient hasn't changed, but I think the setWebChromeClient no longer works on the kitkat webview, or at least not the openFileChooser function.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Update 2: There is a simpler plugin to use with phonegap/cordova

https://github.com/MaginSoft/MFileChooser

Update: Sample project with Cesidio DiBenedetto plugin

https://github.com/jcesarmobile/FileBrowserAndroidTest

I opened an issue on the android open source project and the answer was:

Status: WorkingAsIntended

unfortunately, openFileChooser is not a public API. We are working on a public API in future releases of Android.

For those using phonegap/cordova, this workaround was posted on the bug tracker:

Cesidio DiBenedetto added a comment - 28/Mar/14 01:27

Hey all, I've been experiencing this issue as well so I wrote a Cordova FileChooser plugin to a "band-aid" for the time being. Basically, in Android 4.4(KitKat), as mentioned in previous comments, the file dialog is not opened. However the onclick event is still fired on so you can call the FileChooser plugin to open a file dialog and upon selection, you can set a variable that contains the full path to the file. At this point, you can use the FileTransfer plugin to upload to your server and hook into the onprogress event to show progress. This plugin is mainly configured for Android 4.4 so I would recommend to continue to use the native file dialogs for earlier versions of Android. There might be issues with the plugin as I have not fully tested all possible scenarios on many devices, but I have installed it on a Nexus 5 and it worked fine.

https://github.com/cdibened/filechooser

Not tested it because I built my own workaround

A comment form a chromium developer

We will be a adding a public API to WebViewClient in next major release to handle file requests.

It seems they consider it as a bug now and they are going to fix it


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...