File Handling
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 properties in app/src/main/assets/swv.properties:
# Globally enable/disable file input.
feature.uploads=true
# Include a camera capture option in the chooser.
feature.camera.uploads=true
# Allow multiple file selection if the HTML input tag supports it.
feature.multiple.uploads=true
Permissions:
The following permissions are declared in AndroidManifest.xml and requested at runtime if needed:
android.permission.CAMERAandroid.permission.READ_MEDIA_IMAGESandroid.permission.READ_MEDIA_VIDEOandroid.permission.WRITE_EXTERNAL_STORAGE(for older Android versions)
How it Works:
- A user taps an
<input type="file">element in the WebView. - The
onShowFileChoosermethod inFileProcessing.javais triggered. - It constructs an
Intentthat opens a system chooser, allowing the user to select files or use the camera (if enabled). - The HTML
acceptattribute can filter the file types shown (e.g.,image/*). - The HTML
multipleattribute, combined withfeature.multiple.uploads, 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
DownloadListenerdetects a URL that triggers a download. - It uses the Android
DownloadManagerservice 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.