Skip to content
webtoapkfree

Does file upload work in an Android WebView?

WebView file upload works only if the app overrides onShowFileChooser. By default Android WebView cancels every file request, so the button does nothing.

GuidesNookesh Karri

Light cover card with the title 'Does file upload work in an Android WebView?' in dark text and a green accent bar

WebView file upload works on Android, but not by default. A plain WebView ignores <input type="file"> until the app overrides onShowFileChooser in its WebChromeClient and returns the chosen file. If your upload button does nothing inside an app but works in Chrome, that missing handler is almost always the reason.

Why the upload button does nothing in a WebView

An upload button does nothing in a WebView because Android hands the request to the app, and the app has no handler. The WebChromeClient reference says onShowFileChooser “Asks the client app to show a file chooser” when a page wants a file, such as from a file input in a form or a JavaScript call.

The same page states the default plainly: “The default behavior is that WebView will cancel all file requests.” No error, no dialog. The tap just disappears.

Chrome works because Chrome is a full browser with its own picker. A WebView is only the rendering engine, so the app around it must supply the picker, the same way it must supply a download handler and camera permission handling.

How WebView file upload works

WebView file upload is a short handshake between the page, the WebView and your app. The method was added in API level 21, so it’s available on every phone a modern app supports.

  1. The user taps a file input on your page.
  2. WebView calls onShowFileChooser with three things: the WebView, a filePathCallback and a FileChooserParams object.
  3. Your override returns true, which tells WebView you will answer the callback. Returning false means default handling, which cancels.
  4. Your app shows a picker, the camera or anything else.
  5. When the user picks a file, you call filePathCallback.onReceiveValue() with an array of file URIs.
  6. The page’s input now holds the file, and its form or JavaScript uploads it as usual.

The reference describes the callback’s job exactly: “Invoke this callback to supply the list of paths to files to upload, or null to cancel.” It must only be called when your override returned true.

Reading what the page asked for

The page’s input attributes reach your app through FileChooserParams, so you can open the right picker. MDN’s file input page says accept “defines the file types the file input should accept” and multiple lets the user select more than one file.

The FileChooserParams reference maps those to methods:

Page attribute What your app reads What it tells you
accept="image/*" getAcceptTypes() An array of MIME types, possibly partial like audio/*, or empty
multiple getMode() MODE_OPEN_MULTIPLE instead of MODE_OPEN
capture isCaptureEnabled() The page prefers a live camera or microphone capture
none (save request) getMode() MODE_SAVE, picking a new file to save

A newer MODE_OPEN_FOLDER mode lets a page pick a folder, but the reference lists it as added in API level 37. Don’t build on it yet.

The minimal Kotlin handler

The minimal handler stores the callback, launches the picker that createIntent() builds, and returns the result. This version uses the Activity Result API:

private var fileCallback: ValueCallback<Array<Uri>>? = null

private val picker = registerForActivityResult(
    ActivityResultContracts.StartActivityForResult()
) { result ->
    val uris = WebChromeClient.FileChooserParams
        .parseResult(result.resultCode, result.data)
    fileCallback?.onReceiveValue(uris) // null when cancelled
    fileCallback = null
}

webView.webChromeClient = object : WebChromeClient() {
    override fun onShowFileChooser(
        view: WebView,
        callback: ValueCallback<Array<Uri>>,
        params: FileChooserParams
    ): Boolean {
        fileCallback?.onReceiveValue(null)
        fileCallback = callback
        picker.launch(params.createIntent())
        return true
    }
}

parseResult returns null when the user cancels, and that null still goes to the callback. And a new request first cancels any older one that was never answered.

Wrap the launch call in a try block for ActivityNotFoundException. On a phone with no app that handles the intent, you should cancel the callback and tell the user.

The cancel trap: why uploads work only once

Uploads that work once and then stop are caused by an unanswered callback. If the user opens the picker and presses back, your app must still call the callback with null. The reference names null as the way “to cancel the request”.

Skip it and the page waits forever. Later taps on the input do nothing. This is the bug I see most in hand-written wrappers, because a quick test only covers picking a file. Always test the cancel path: open the picker, back out, then try to upload again.

Camera uploads and the capture attribute

A camera upload needs its own intent, because the built-in picker may not offer the camera. MDN’s capture attribute page lists two values: user for the user-facing camera and environment for the outward-facing one. The attribute has limited availability, so treat it as a hint.

The FileChooserParams reference warns that with createIntent(), “Some advanced sources (for example, live media capture) may not be supported”. Apps that want them “should build their own Intent”. So when isCaptureEnabled() is true, launch a camera intent yourself, and don’t use parseResult for that result; the reference says to use it only when media capture was not requested.

A camera intent also needs the camera permission flow. My camera and microphone guide covers the manifest entry and the runtime prompt.

Using the Android photo picker for images

For image and video uploads, the Android photo picker is a cleaner choice than a generic file browser. The photo picker guide says it gives “a safe, built-in way for users to grant your app access to only selected images and videos”.

The picker runs on Android 11 (API level 30) or higher with Google System Updates. A backported version can be installed on Android 4.4 (API level 19) through Android 10 (API level 29) on devices with Google Play services. If getAcceptTypes() asks only for images, route the request to the photo picker; for PDFs and other files, keep createIntent().

Treat returned files as untrusted

The URIs that come back from a picker must be treated as untrusted. The FileChooserParams reference says the intent may be handled by another app, and that “WebView does not enforce any restrictions on the returned Uris.”

A malicious picker could return a URI that points at your own app’s private files, and your page would upload them. Before you pass URIs to the callback, check that they are content URIs from a provider you expect and not paths inside your app’s own data folder.

What to check when WebView file upload still fails

If uploads still fail after adding the handler, match the symptom to the cause:

Symptom Likely cause
Tap does nothing at all No onShowFileChooser override, or it returns false
Works once, then never again Callback not answered with null on cancel
Picker opens, file never reaches the page Callback not called, or called with the wrong URIs
Only images show, PDFs are hidden Your intent ignores getAcceptTypes() or forces an image type
Camera never appears createIntent() used for a capture request
Upload stops after sign-in Session problem, not the picker; see the Google sign-in guide

Test on a real phone. An emulator without a camera or file manager app can hide or invent failures.

What if you built the app with a no-code converter?

With a no-code converter, file upload depends entirely on whether the wrapper’s native code includes a file chooser handler. You can’t add one from your website’s side, because the handler lives in the app.

Web2Apk’s own guides say it doesn’t guarantee every website works in a WebView, and that downloads and permissions can behave differently than in Chrome. Generated apps need Android 8.0 or newer. Before you share a build, install the APK and try every upload field your site has, including cancelling the picker. The website to APK guide lists the other features to test, and the conversion walkthrough covers the full build.

If uploads fail in the test build, the fix is a hand-written wrapper with the handler above.

FAQ

Why does my file upload button do nothing in a WebView app?

The app hasn’t overridden onShowFileChooser in its WebChromeClient. Android’s documentation says the default behavior is that WebView cancels all file requests, so the tap is ignored.

Why does the upload button stop working after I cancel the picker once?

The app didn’t answer the stored callback when the user backed out. The callback must still be called, with null, to cancel the request. Until it is, the page keeps waiting.

Can a WebView upload open the camera?

Yes, but the app has to handle it. The page can ask with the capture attribute, and the app can read that through isCaptureEnabled. The default intent from createIntent may not support live media capture, so the app builds its own camera intent.

Does WebView support multiple file uploads?

Yes, when the input has the multiple attribute and the app supports it. The app sees MODE_OPEN_MULTIPLE from getMode and must let the picker return more than one file.

Does file upload work in a no-code WebView app?

Only if the wrapper’s native code handles the file chooser. Install a test build on a real phone and try every upload field on your site before you publish.

Sources