Added in API level 21

FileChooserParams


abstract class FileChooserParams
kotlin.Any
   ↳ android.webkit.WebChromeClient.FileChooserParams

Parameters used in the onShowFileChooser method.

Summary

Constants
static Int

Open single file.

static Int

Like Open but allows multiple files to be selected.

static Int

Allows picking a nonexistent file and saving it.

Public constructors

Public methods
abstract Intent!

Creates an intent that would start a file picker for file selection.

abstract Array<String!>!

Returns an array of acceptable MIME types.

abstract String?

The file name of a default selection if specified, or null.

abstract Int

Returns file chooser mode.

abstract CharSequence?

Returns the title to use for this file selector.

abstract Boolean

Returns preference for a live media captured value (e.g. Camera, Microphone).

open static Array<Uri!>?
parseResult(resultCode: Int, data: Intent!)

Parse the result returned by the file picker activity.

Constants

MODE_OPEN

Added in API level 21
static val MODE_OPEN: Int

Open single file. Requires that the file exists before allowing the user to pick it.

Value: 0

MODE_OPEN_MULTIPLE

Added in API level 21
static val MODE_OPEN_MULTIPLE: Int

Like Open but allows multiple files to be selected.

Value: 1

MODE_SAVE

Added in API level 21
static val MODE_SAVE: Int

Allows picking a nonexistent file and saving it.

Value: 3

Public constructors

FileChooserParams

FileChooserParams()

Public methods

createIntent

Added in API level 21
abstract fun createIntent(): Intent!

Creates an intent that would start a file picker for file selection. The Intent supports choosing files from simple file sources available on the device. Some advanced sources (for example, live media capture) may not be supported and applications wishing to support these sources or more advanced file operations should build their own Intent.

How to use:

  1. Build an intent using createIntent
  2. Fire the intent using android.app.Activity#startActivityForResult.
  3. Check for ActivityNotFoundException and take a user friendly action if thrown.
  4. Listen the result using android.app.Activity#onActivityResult
  5. Parse the result using parseResult only if media capture was not requested.
  6. Send the result using filePathCallback of android.webkit.WebChromeClient#onShowFileChooser

Note: The created intent may be handled by third-party applications on device. The received result must be treated as untrusted as it can contain Uris pointing to your own app's sensitive data files. Your app should check the resultant Uris in parseResult before calling the filePathCallback.

Return
Intent! an Intent that supports basic file chooser sources.

getAcceptTypes

Added in API level 21
abstract fun getAcceptTypes(): Array<String!>!

Returns an array of acceptable MIME types. The returned MIME type could be partial such as audio/*. The array will be empty if no acceptable types are specified.

getFilenameHint

Added in API level 21
abstract fun getFilenameHint(): String?

The file name of a default selection if specified, or null.

getMode

Added in API level 21
abstract fun getMode(): Int

Returns file chooser mode.

getTitle

Added in API level 21
abstract fun getTitle(): CharSequence?

Returns the title to use for this file selector. If null a default title should be used.

isCaptureEnabled

Added in API level 21
abstract fun isCaptureEnabled(): Boolean

Returns preference for a live media captured value (e.g. Camera, Microphone). True indicates capture is enabled, false disabled. Use getAcceptTypes to determine suitable capture devices.

parseResult

Added in API level 21
open static fun parseResult(
    resultCode: Int,
    data: Intent!
): Array<Uri!>?

Parse the result returned by the file picker activity. This method should be used with createIntent. Refer to createIntent for how to use it.

Note: The intent returned by the file picker activity should be treated as untrusted. A third-party app handling the implicit intent created by createIntent might return Uris that the third-party app itself does not have access to, such as your own app's sensitive data files. WebView does not enforce any restrictions on the returned Uris. It is the app's responsibility to ensure that the untrusted source (such as a third-party app) has access the Uris it has returned and that the Uris are not pointing to any sensitive data files.

Parameters
resultCode Int: the integer result code returned by the file picker activity.
data Intent!: the intent returned by the file picker activity.
Return
Array<Uri!>? the Uris of selected file(s) or null if the resultCode indicates activity canceled or any other error.