All articles

Technical

How File Uploads Work Inside an Android TWA

October 24, 2026 · 6 min read

When converting a Progressive Web App into a native Android app, developers frequently worry about how native system capabilities will behave. One of the most common points of friction in mobile app development is managing file uploads and device storage access. If you have ever built a traditional hybrid app using a standard Android WebView, you are likely familiar with the extensive configuration required to make a simple file input work. Trusted Web Activities simplify this process by leveraging the underlying engine of the user default browser.

The WebView File Upload Headache

In a standard Android WebView wrapper, the default behavior for file uploads is completely broken. When a user taps an HTML file input inside a basic WebView, nothing happens. To fix this, developers must write complex native Java or Kotlin code within their Android project. This requires overriding the WebChromeClient class and manually implementing the onShowFileChooser method. Developers must write custom code to handle Android file intent pickers, manage activity results, handle various Android API levels, and request storage permissions at runtime. This adds hundreds of lines of boilerplate code to maintain, troubleshoot, and test across different Android versions.

How Trusted Web Activities Solve the Problem

A Trusted Web Activity avoids these issues entirely. Instead of using a limited and isolated system WebView, a TWA runs inside a secure, full-featured browser container, typically powered by Google Chrome. Because the TWA environment inherits the full capabilities of the modern browser, all standard HTML5 file upload APIs work out of the box with zero native configuration required. When a user taps a file input inside your TWA, Chrome intercepts the action and handles the native system dialog. The user is presented with the familiar system file selector, allowing them to browse local storage, cloud storage providers like Google Drive, and recent downloads.

Mapping HTML Input Types to Android Actions

Because TWAs rely on the browser, standard web features translate directly into native system experiences. You can control how the Android file picker behaves using standard HTML input attributes. The table below details how common HTML file upload formats translate into native Android interfaces.

HTML Code PatternTarget File TypesAndroid System Behavior
<input type='file'>All File TypesOpens the default system file picker showing recent files, downloads, and storage locations.
<input type='file' accept='image/*'>Images OnlyFilters the file picker to display only image galleries and native photo albums.
<input type='file' accept='image/*' capture='environment'>Camera AccessLaunches the system camera app directly to capture a new photo.
<input type='file' accept='video/*' capture='user'>Front Camera VideoLaunches the front-facing video recorder directly to record a clip.
<input type='file' multiple>Multiple FilesEnables multi-select mode in the Android file selector, allowing users to select several items at once.

Understanding Permissions in a TWA

Another major benefit of the TWA architecture is how permission management is delegated. When you run a web app in a standard WebView, you must declare sensitive permissions like READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE, or CAMERA in your AndroidManifest.xml file. You must also write custom Java or Kotlin logic to request these permissions from the user at runtime. This can raise suspicion during Google Play Store reviews, as Google strictly scrutinises apps requesting broad storage or hardware access.

With a Trusted Web Activity, you do not need to request these sensitive permissions in your native AndroidManifest.xml shell. When a user interacts with a file input or requests camera access through the browser container, Google Chrome handles the permission delegation. If your web app requests access to the camera using the MediaDevices API, the browser requests the permission from the user under the browser context. Because the browser has already secured the necessary system-level access, your native app wrapper remains lightweight and clean, reducing the risk of Play Store policy rejections related to unnecessary permission requests.

Handling the Media Capture API

To provide a genuinely native feel, you can use the HTML5 Media Capture API. This is particularly useful for document scanning, profile picture uploads, or scanning QR codes. By adding the capture attribute to your file inputs, you tell the Android system to bypass the generic file explorer and launch the native camera interface directly. For example, if your web app includes <input type='file' accept='image/*' capture='environment'>, tapping this input on an Android device running your TWA will open the system camera. Once the user takes a photo and confirms, the image file is automatically passed back to your PWA Javascript context as a standard File object, which you can process or upload to your servers.

Best Practices for Reliable TWA File Uploads

To ensure your file upload workflows are completely seamless inside a TWA, you should implement the following recommendations in your PWA codebase:

  • Provide clear loading indicators: When users upload large files such as high-resolution images or videos over mobile networks, provide visual progress bars. Since the TWA does not display a browser address bar, users need explicit feedback that the upload is progressing.
  • Validate file types on both client and server: Do not rely solely on the HTML accept attribute. Users can sometimes bypass filters through external file managers, so ensure your web application validates file formats and sizes upon receipt.
  • Optimise image sizes before uploading: Use modern web APIs like the Canvas API or compression libraries to compress images on the client side before sending them to your server. This reduces data usage and improves the performance of your app.
  • Gracefully handle cancellation: If a user opens the camera or file picker and then closes it without selecting a file, ensure your web application interface resets properly and remains functional.

By relying on the robust web standards built into the Android browser ecosystem, Trusted Web Activities eliminate the friction of building and maintaining custom file upload bridges. Your PWA remains standard-compliant, easier to maintain, and completely functional on any Android device.

Ready to ship your Android app?

Paste your PWA URL, get a signed APK and a Google Play ready AAB in minutes.

Build my app