File Handling
Smart WebView provides robust support for handling file uploads initiated from your web content, including direct access to the device camera, and manages file downloads.
File Uploads & Camera Access
This functionality allows users to interact with <input type="file">
elements in your web content.
Configuration:
Controlled by variables in SmartWebView.java
:
ASWP_FUPLOAD
(true
/false
): Globally enable/disable file input.ASWP_CAMUPLOAD
(true
/false
): Include a camera capture option in the chooser.ASWP_MULFILE
(true
/false
): Allow multiple file selection if the HTML input tag supports it.
Permissions:
The following permissions are declared in AndroidManifest.xml
and requested at runtime if needed:
android.permission.CAMERA
android.permission.READ_MEDIA_IMAGES
android.permission.READ_MEDIA_VIDEO
android.permission.READ_MEDIA_AUDIO
android.permission.WRITE_EXTERNAL_STORAGE
(withmaxSdkVersion
for older Android versions)
How it Works:
- A user taps an
<input type="file">
element in the WebView. - The
onShowFileChooser
method inFileProcessing.java
is triggered. - It constructs an
Intent
that opens a system chooser, allowing the user to select files or use the camera (if enabled). - The HTML
accept
attribute can filter the file types shown (e.g.,image/*
). - The HTML
multiple
attribute, combined withASWP_MULFILE
, allows for multi-file selection. - The selected file URIs are returned to the WebView to be processed by your web application.
Downloads
This handles files downloaded from the WebView.
How it Works:
- The WebView’s
DownloadListener
detects a URL that triggers a download. - It uses the Android
DownloadManager
service to handle the download. - A system notification shows the download progress.
- Files are saved to the public “Downloads” directory on the device.
- A Toast message confirms that the download has started.