pub trait PublicStorage<R: Runtime> {
// Required methods
fn create_file_in_public_dir(
&self,
dir: impl Into<PublicDir>,
relative_path_with_subdir: impl AsRef<str>,
mime_type: Option<&str>,
) -> Result<FileUri>;
fn is_audiobooks_dir_available(&self) -> Result<bool>;
fn is_recordings_dir_available(&self) -> Result<bool>;
fn app_handle(&self) -> &AppHandle<R>;
// Provided method
fn create_file_in_public_app_dir(
&self,
dir: impl Into<PublicDir>,
relative_path: impl AsRef<str>,
mime_type: Option<&str>,
) -> Result<FileUri> { ... }
}Expand description
File storage intended for the app’s use only.
Required Methods§
Sourcefn create_file_in_public_dir(
&self,
dir: impl Into<PublicDir>,
relative_path_with_subdir: impl AsRef<str>,
mime_type: Option<&str>,
) -> Result<FileUri>
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 read-write-removable URI.
If a file with the same name already exists, a sequential number is added to the name.
Missing subdirectories will be created recursively.
The created file will be registered with the corresponding MediaStore as needed.
The uri will remain valid only until the app is uninstalled.
§Note
Do not save files directly in the public directory. Please specify a subdirectory in the relative_path_with_sub_dir, such as appName/file.txt or appName/2025-2-11/file.txt. Do not use file.txt.
mime_type specify the type of the file to be created.
It should be provided whenever possible.
If not specified, application/octet-stream is used, as generic, unknown, or undefined file types.
When using PublicImageDir, please do not use a mime_type other than image types.
This may result in an error.
Similarly, do not use non-corresponding media types for PublicVideoDir or PublicAudioDir.
Only PublicGeneralPurposeDir allows all mime types.
§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.
Sourcefn is_audiobooks_dir_available(&self) -> Result<bool>
fn is_audiobooks_dir_available(&self) -> Result<bool>
Verify whether PublicAudioDir::Audiobooks is available on a given device.
§Support
All Android version.
Sourcefn is_recordings_dir_available(&self) -> Result<bool>
fn is_recordings_dir_available(&self) -> Result<bool>
Verify whether PublicAudioDir::Recordings is available on a given device.
§Support
All Android version.
fn app_handle(&self) -> &AppHandle<R>
Provided Methods§
Sourcefn create_file_in_public_app_dir(
&self,
dir: impl Into<PublicDir>,
relative_path: impl AsRef<str>,
mime_type: Option<&str>,
) -> Result<FileUri>
fn create_file_in_public_app_dir( &self, dir: impl Into<PublicDir>, relative_path: impl AsRef<str>, mime_type: Option<&str>, ) -> Result<FileUri>
Creates a new empty file in the specified public app directory and returns a read-write-removable URI.
If a file with the same name already exists, a sequential number is added to the name.
Missing subdirectories will be created recursively.
The created file will be registered with the corresponding MediaStore as needed.
The URI will remain valid only until the app is uninstalled.
§Note
mime_type specify the type of the file to be created.
It should be provided whenever possible.
If not specified, application/octet-stream is used, as generic, unknown, or undefined file types.
When using PublicImageDir, please do not use a mime_type other than image types.
This may result in an error.
Similarly, do not use non-corresponding media types for PublicVideoDir or PublicAudioDir.
Only PublicGeneralPurposeDir allows all mime types.
§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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.