FilePicker

Struct FilePicker 

Source
pub struct FilePicker<'a, R: Runtime>(/* private fields */);
Expand description

API of file/dir picker.

§Examples

fn example(app: &tauri::AppHandle) {
    use tauri_plugin_android_fs::AndroidFsExt as _;
 
    let api = app.android_fs();
    let file_picker = api.file_picker();
}

Implementations§

Source§

impl<'a, R: Runtime> FilePicker<'a, R>

Source

pub fn pick_files( &self, initial_location: Option<&FileUri>, mime_types: &[&str], multiple: bool, ) -> Result<Vec<FileUri>>

Opens a system file picker and returns a read-write URIs.
If no file is selected or the user cancels, an empty vec is returned.

By default, returned URI is valid until the app is terminated. If you want to persist it across app restarts, use AndroidFs::take_persistable_uri_permission.

This provides a standardized file explorer-style interface, and also allows file selection from part of third-party apps or cloud storage.

Removing the returned files is also supported in most cases, but note that files provided by third-party apps may not be removable.

§Args
§Support

All.

§References

https://developer.android.com/reference/android/content/Intent#ACTION_OPEN_DOCUMENT

Source

pub fn pick_file( &self, initial_location: Option<&FileUri>, mime_types: &[&str], ) -> Result<Option<FileUri>>

Opens a system file picker and returns a read-write URI.
If no file is selected or the user cancels, None is returned.

By default, returned URI is valid until the app is terminated. If you want to persist it across app restarts, use AndroidFs::take_persistable_uri_permission.

This provides a standardized file explorer-style interface, and also allows file selection from part of third-party apps or cloud storage.

Removing the returned files is also supported in most cases, but note that files provided by third-party apps may not be removable.

§Args
§Support

All.

§References

https://developer.android.com/reference/android/content/Intent#ACTION_OPEN_DOCUMENT

Source

pub fn pick_visual_medias( &self, target: VisualMediaTarget, multiple: bool, ) -> Result<Vec<FileUri>>

Opens a media picker and returns a readonly URIs.
If no file is selected or the user cancels, an empty vec is returned.

By default, returned URI is valid until the app is terminated. If you want to persist it across app restarts, use AndroidFs::take_persistable_uri_permission.

This media picker provides a gallery, sorted by date from newest to oldest.

§Args
  • target :
    The media type of the file to be selected.
    Images or videos, or both.

  • multiple :
    Indicates whether multiple file selection is allowed.

§Note

The file obtained from this function cannot retrieve the correct file name using AndroidFs::get_name.
Instead, it will be assigned a sequential number, such as 1000091523.png. And this is marked intended behavior, not a bug.

§Support

This feature is available on devices that meet the following criteria:

  • Running Android 11 (API level 30) or higher
  • Receive changes to Modular System Components through Google System Updates

Availability on a given device can be verified by calling FilePicker::is_visual_media_picker_available.
If not supported, this function behaves the same as FilePicker::pick_files.

§References

https://developer.android.com/training/data-storage/shared/photopicker

Source

pub fn pick_visual_media( &self, target: VisualMediaTarget, ) -> Result<Option<FileUri>>

Opens a media picker and returns a readonly URI.
If no file is selected or the user cancels, None is returned.

By default, returned URI is valid until the app is terminated. If you want to persist it across app restarts, use AndroidFs::take_persistable_uri_permission.

This media picker provides a gallery, sorted by date from newest to oldest.

§Args
  • target :
    The media type of the file to be selected.
    Images or videos, or both.
§Note

The file obtained from this function cannot retrieve the correct file name using AndroidFs::get_name.
Instead, it will be assigned a sequential number, such as 1000091523.png. And this is marked intended behavior, not a bug.

§Support

This feature is available on devices that meet the following criteria:

  • Running Android 11 (API level 30) or higher
  • Receive changes to Modular System Components through Google System Updates

Availability on a given device can be verified by calling FilePicker::is_visual_media_picker_available.
If not supported, this function behaves the same as FilePicker::pick_file.

§References

https://developer.android.com/training/data-storage/shared/photopicker

Source

pub fn pick_contents( &self, mime_types: &[&str], multiple: bool, ) -> Result<Vec<FileUri>>

Opens a file picker and returns a readonly URIs.
If no file is selected or the user cancels, an empty vec is returned.

Returned URI is valid until the app is terminated. Can not persist it.

This works differently depending on the model and version.
Recent devices often have the similar behaviour as FilePicker::pick_visual_medias or FilePicker::pick_files.
In older versions, third-party apps often handle request instead.

§Args
  • mime_types :
    The MIME types of the file to be selected.
    However, there is no guarantee that the returned file will match the specified types.
    If left empty, all file types will be available (equivalent to ["*/*"]).

  • multiple :
    Indicates whether multiple file selection is allowed.

§Support

All.

§References

https://developer.android.com/reference/android/content/Intent#ACTION_GET_CONTENT

Source

pub fn pick_content(&self, mime_types: &[&str]) -> Result<Option<FileUri>>

Opens a file picker and returns a readonly URI.
If no file is selected or the user cancels, None is returned.

Returned URI is valid until the app is terminated. Can not persist it.

This works differently depending on the model and version.
Recent devices often have the similar behaviour as FilePicker::pick_visual_media or FilePicker::pick_file.
In older versions, third-party apps often handle request instead.

§Args
  • mime_types :
    The MIME types of the file to be selected.
    However, there is no guarantee that the returned file will match the specified types.
    If left empty, all file types will be available (equivalent to ["*/*"]).
§Support

All.

§References

https://developer.android.com/reference/android/content/Intent#ACTION_GET_CONTENT

Source

pub fn pick_dir( &self, initial_location: Option<&FileUri>, ) -> Result<Option<FileUri>>

Opens a system directory picker, allowing the creation of a new directory or the selection of an existing one, and returns a read-write directory URI. App can fully manage entries within the returned directory.
If no directory is selected or the user cancels, None is returned.

By default, returned URI is valid until the app is terminated. If you want to persist it across app restarts, use AndroidFs::take_persistable_uri_permission.

This provides a standardized file explorer-style interface, and also allows directory selection from part of third-party apps or cloud storage.

§Args
§Support

All.

§References

https://developer.android.com/reference/android/content/Intent#ACTION_OPEN_DOCUMENT_TREE

Source

pub fn save_file( &self, initial_location: Option<&FileUri>, initial_file_name: impl AsRef<str>, mime_type: Option<&str>, ) -> Result<Option<FileUri>>

Opens a system file saver and returns a writeonly URI.
The returned file may be a newly created file with no content, or it may be an existing file with the requested MIME type.
If the user cancels, None is returned.

By default, returned URI is valid until the app is terminated. If you want to persist it across app restarts, use AndroidFs::take_persistable_uri_permission.

This provides a standardized file explorer-style interface, and also allows file selection from part of third-party apps or cloud storage.

Removing and reading the returned files is also supported in most cases, but note that files provided by third-party apps may not.

§Args
§Support

All.

§References

https://developer.android.com/reference/android/content/Intent#ACTION_CREATE_DOCUMENT

Source

pub fn is_visual_media_picker_available(&self) -> Result<bool>

Verify whether FilePicker::pick_visual_medias is available on a given device.

§Support

All.

Auto Trait Implementations§

§

impl<'a, R> Freeze for FilePicker<'a, R>

§

impl<'a, R> RefUnwindSafe for FilePicker<'a, R>

§

impl<'a, R> Send for FilePicker<'a, R>

§

impl<'a, R> Sync for FilePicker<'a, R>

§

impl<'a, R> Unpin for FilePicker<'a, R>

§

impl<'a, R> UnwindSafe for FilePicker<'a, R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,