Skip to main content

AndroidStorage

Kindclass
Packageandroid.platform
Full nameandroid.platform.AndroidStorage
Sourcesource/android/platform/AndroidStorage.hx

Android Storage Access Framework (SAF) integration plus content:// URI support. Use this to import/export user files through the native document picker (ACTION_OPEN_DOCUMENT, ACTION_CREATE_DOCUMENT, ACTION_OPEN_DOCUMENT_TREE).

Picker results arrive through onResult with the document URI, display name and (for open requests) the file contents.

Public fields​

NameTypeStaticDefaultNotes
REQUEST_OPEN_DOCUMENTIntyes9101final · Request codes, mirrored from PhoenixStorage.java.
REQUEST_CREATE_DOCUMENTIntyes9102final
REQUEST_OPEN_DOCUMENT_TREEIntyes9103final
onResultFlxTypedSignal<AndroidStorageResult->Void>yes—property (get, never) · Fired with every picker result (including cancellation).

Public methods​

openDocument​

static function openDocument(?mimeTypes:String, ?title:String):Void

Opens the native document picker. @param mimeTypes comma separated MIME types, e.g. "application/json" (empty/null = any type).

ParameterTypeDefault
mimeTypes (optional)String—
title (optional)String—

View source

openDocumentByExtensions​

static function openDocumentByExtensions(extensions:Array<String>, ?title:String):Void

Convenience wrapper for openDocument with a list of extensions mapped to MIME types.

ParameterTypeDefault
extensionsArray<String>—
title (optional)String—

View source

createDocument​

static function createDocument(mime:String, suggestedName:String):Void

Opens the native "create file" picker (save-as).

ParameterTypeDefault
mimeString—
suggestedNameString—

View source

openDocumentTree​

static function openDocumentTree():Void

Opens the native directory picker.

View source

isContentUri​

static function isContentUri(uri:String):Bool
ParameterTypeDefault
uriString—

View source

readUriBytes​

static function readUriBytes(uri:String):Null<Bytes>

Reads a content:// URI into memory.

ParameterTypeDefault
uriString—

View source

readUriText​

static function readUriText(uri:String):Null<String>

Reads a content:// URI as UTF-8 text.

ParameterTypeDefault
uriString—

View source

writeUriBytes​

static function writeUriBytes(uri:String, data:Bytes):Bool

Writes bytes to a content:// URI previously returned by createDocument.

ParameterTypeDefault
uriString—
dataBytes—

View source

writeUriText​

static function writeUriText(uri:String, text:String):Bool
ParameterTypeDefault
uriString—
textString—

View source

getDisplayName​

static function getDisplayName(uri:String):String

Display name of a content:// (or file) URI, "" when unknown.

ParameterTypeDefault
uriString—

View source

getUriSize​

static function getUriSize(uri:String):Int

Size in bytes of a content:// (or file) URI, -1 when unknown.

ParameterTypeDefault
uriString—

View source

importUri​

static function importUri(uri:String, destinationPath:String):Null<String>

Copies a content:// URI into the app's storage directory so it can be used through regular filesystem paths. Returns the destination path or null on failure.

ParameterTypeDefault
uriString—
destinationPathString—

View source

exportFileToUri​

static function exportFileToUri(filePath:String, uri:String):Bool

Copies a regular file into a content:// URI (for export flows).

ParameterTypeDefault
filePathString—
uriString—

View source

persistUriPermission​

static function persistUriPermission(uri:String, writable:Bool = true):Void

Persists read/write permission grants for a picked URI across reboots.

ParameterTypeDefault
uriString—
writable (optional)Booltrue

View source

extensionToMime​

static function extensionToMime(extension:String):Null<String>

Maps common file extensions to MIME types.

ParameterTypeDefault
extensionString—

View source

Internals​

Private / internal members
FieldTypeStatic
_openDocumentDynamicyes
_createDocumentDynamicyes
_openDocumentTreeDynamicyes
_readUriBytesDynamicyes
_writeUriBytesDynamicyes
_getDisplayNameDynamicyes
_getUriSizeDynamicyes
_copyUriToFileDynamicyes
_persistUriPermissionDynamicyes
Method
static inline function get_onResult():FlxTypedSignal<AndroidStorageResult->Void>
static function openDocument_jni(mimeTypes:String, title:String):Void
static function createDocument_jni(mime:String, name:String):Void
static function openDocumentTree_jni():Void
static function readUriBytes_jni(uri:String):Dynamic
static function writeUriBytes_jni(uri:String, data:Dynamic):Bool
static function getDisplayName_jni(uri:String):String
static function getUriSize_jni(uri:String):Float
static function copyUriToFile_jni(uri:String, destination:String):Bool
static function persistUriPermission_jni(uri:String, writable:Bool):Void