HTML file input in android webview (android 4.4, kitkat)
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
Webpage to choose and upload file for Android 4.4.2 stock browser
No, there's no way to get this working on Android 4.4.2.
All you can do is intercept the onclick
or onchange
events on the <input type="file">
because these are still fired.
HTML input type file with android 4.4
Seems you want to use the PhoneGap FileTransfer method which according to the docs "The FileTransfer object allows you to upload or download files to and from a server." which is exactly what you need. There is a code example there that should get you started.
UPDATE (by request from your comment):
One form is not really designed to "include" another form however any of the fields that are included inside the "form" tag will be transmitted with the submit to the server (in the form of "Name1=value1&Name2=value2&",etc) so instead of having two forms you can just have multiple fields under one form tag.
How do I print a WebView using KitKat 4.4 print API via reflection?
It's an old one but printing is kind of usefull so this could be good to work correctly. (Without reflection ;))
A better way to work with devices version. No try-catch needed, just need to add some messages before the return or you just hide the button/menu/... depending on the same condition.
@TargetApi(Build.VERSION_CODES.KITKAT)
private void createWebPrintJob(WebView webView) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
return;
// Get a PrintManager instance
PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);
// Get a print adapter instance
PrintDocumentAdapter printAdapter = webView.createPrintDocumentAdapter();
// Create a print job with name and adapter instance
String jobName = getString(R.string.app_name) + " Document";
printManager.print(jobName, printAdapter,
new PrintAttributes.Builder().build());
}
The printJob will be execute only with SDK 19 and above
Related Topics
How to Connect Localhost in the Android Emulator
How to Completely Rename an Android Application
Android.Support.V7.App.Activitycompat Not Found
How to Convert Image to Zpl Code for Printing Using Zebra Printer
How to Fix Mainactivity Does Not Have a Navcontroller
How to Make a Link Open an Instagram Page in an App Installed on Android
How to Transfer from One Fragment to Another in Android
Refresh/Reload/Re Instantiate a Fragment in an Android Tab System
Android Studio - Failed to Apply Plugin [Id 'Com.Android.Application']
How to Set Transparency of a Background Image Android Xml File
How to Set the Height of an Item Row in Gridlayoutmanager
Android: Textview: Remove Spacing and Padding on Top and Bottom
Android How to Get Current Positon on Recyclerview That User Scrolled to Item
How to Declare Global Variables in Android
Socket.Io Client Getting Connected Disconnected Repeatedly