pub struct PrivateStorage<'a, R: Runtime> { /* private fields */ }Expand description
API of file storage intended for the app’s use only.
§Examples
use tauri_plugin_android_fs::{AndroidFsExt, PrivateDir};
async fn example(app: &tauri::AppHandle) {
let api = app.android_fs_async();
let ps = api.private_storage();
// Resolve the absolute paths.
// Files and directories in these locations can be fully managed using `std::fs`.
let cache_dir_path: std::path::PathBuf = ps.resolve_path(PrivateDir::Cache).await?;
let data_dir_path: std::path::PathBuf = ps.resolve_path(PrivateDir::Data).await?;
let nobackup_data_dir_path: std::path::PathBuf = ps.resolve_path(PrivateDir::NoBackupData).await?;
// These directories may also contain files created by other Tauri plugins
// or the WebView runtime. To avoid conflicts, it is recommended to use
// a uniquely named subdirectory for your application.
let cache_dir_path = cache_dir_path.join("01K6049FVCD4SAGMAB6X20SA5S");
let data_dir_path = data_dir_path.join("01K6049FVCD4SAGMAB6X20SA5S");
let nobackup_data_dir_path = nobackup_data_dir_path.join("01K6049FVCD4SAGMAB6X20SA5S");
}Implementations§
Source§impl<'a, R: Runtime> AsyncPrivateStorage<'a, R>
impl<'a, R: Runtime> AsyncPrivateStorage<'a, R>
Sourcepub async fn resolve_path(&self, dir: PrivateDir) -> Result<PathBuf>
pub async fn resolve_path(&self, dir: PrivateDir) -> Result<PathBuf>
Returns the absolute path of an app-specific directory on the internal storage.
Files and directories in this location can be managed directly using std::fs.
This function only constructs the path and does not create the directory.
Since these locations may also contain files created by other Tauri plugins or by the WebView runtime, it is recommended to create a uniquely named subdirectory for your application.
§Notes
Files in these locations are removed when the app is uninstalled.
When using PrivateDir::Cache, the system may automatically delete files
when additional storage space is needed.
Applications should not rely on this behavior and should clear cache files explicitly.
These directories are inaccessible to other apps under normal circumstances. On rooted devices or when the user has elevated privileges, their contents may still be accessible.
The returned path may change if the app is moved to adopted storage. Persist only relative paths if the path needs to be stored.
Each Android user has a separate app-specific directory.
Get an absolute path of the app-specific directory on the internal storage.
App can fully manage entries within this directory via std::fs and etc.
This function does not create any directories; it only constructs the path.
Since these locations may contain files created by other Tauri plugins or webview systems, it is recommended to add a subdirectory with a unique name.
These entries will be deleted when the app is uninstalled and may also be deleted at the user’s initialising request.
When using PrivateDir::Cache, the system will automatically delete entries as disk space is needed elsewhere on the device.
But you should not rely on this. The cache should be explicitly cleared by yourself.
The system prevents other apps and user from accessing these locations. In cases where the device is rooted or the user has special permissions, the user may be able to access this.
Since the returned paths can change when the app is moved to an adopted storage, only relative paths should be stored.
§Note
This provides a separate area for each user in a multi-user environment.
§Support
All Android versions supported by Tauri.