Struct PublicStorage

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

API of file storage that is available to other applications and users.

§Examples

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

Implementations§

Source§

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

Source

pub fn create_file_in_public_app_dir( &self, dir: impl Into<PublicDir>, relative_path: impl AsRef<str>, mime_type: Option<&str>, ) -> Result<FileUri>

See PublicStorage::create_file_in_public_dir for description.

This is the same as following:

create_file_in_public_dir(
    dir,
    format!("{app_name}/{relative_path}"),
    mime_type
);
Source

pub fn create_file_in_public_dir( &self, dir: impl Into<PublicDir>, relative_path_with_subdir: impl AsRef<str>, mime_type: Option<&str>, ) -> Result<FileUri>

Creates a new empty file in the specified public directory and returns a persistent read-write URI.

The created file has following features :

  • Will be registered with the corresponding MediaStore as needed.
  • Always supports remove.
  • Not removed when the app is uninstalled.
§Args
  • dir :
    The base directory.
    When using PublicImageDir, use only image MIME types for mime_type, which is discussed below.; using other types may cause errors. Similarly, use only the corresponding media types for PublicVideoDir and PublicAudioDir. Only PublicGeneralPurposeDir supports all MIME types.

  • relative_path_with_subdir :
    The file path relative to the base directory.
    If a file with the same name already exists, a sequential number will be appended to ensure uniqueness.
    Any missing subdirectories in the specified path will be created automatically.
    Please specify a subdirectory in this, such as MyApp/file.txt or MyApp/2025-2-11/file.txt. Do not use file.txt.
    As shown above, it is customary to specify the app name at the beginning of the subdirectory, and in this case, using PublicStorage::create_file_in_public_app_dir is recommended.

  • mime_type :
    The MIME type of the file to be created.
    If this is None, MIME type is inferred from the extension of relative_path_with_subdir and if that fails, application/octet-stream is used.

§Support

Android 10 (API level 29) or higher.
Lower are need runtime request of WRITE_EXTERNAL_STORAGE. (This option will be made available in the future)

PublicAudioDir::Audiobooks is not available on Android 9 (API level 28) and lower. Availability on a given device can be verified by calling PublicStorage::is_audiobooks_dir_available.
PublicAudioDir::Recordings is not available on Android 11 (API level 30) and lower. Availability on a given device can be verified by calling PublicStorage::is_recordings_dir_available.
Others are available in all Android versions.

Source

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

Verify whether PublicAudioDir::Audiobooks is available on a given device.

§Support

All.

Source

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

Verify whether PublicAudioDir::Recordings is available on a given device.

§Support

All.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<'a, R> UnwindSafe for PublicStorage<'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,

Source§

impl<T> MaybeSendSync for T