On modern android, with Tauri (a rust backend and a javascript frontend), how to ask the user to grant the right to access all files in the 'home' directory (/storage/emulated/0), so all documents, downloads, pictures, videos in addition to external storage devices?
I tried the code below, and It successfully compiles on all platforms, with no errors or warning, And the application runs just fine on Android without any errors or crashes, but user permission is never asked. So it cannot read or even list many essential files. Any idea on what's wrong here?
// rust side ... #[cfg(target_os = "android")] use tauri_plugin_android_fs::{AndroidFsExt}; ... tauri::Builder::default() .plugin(tauri_plugin_android_fs::init()) ... // this is the func to let the app ask the user for minimal storage access #[tauri::command] async fn request_directory_access(app: tauri::AppHandle) { #[cfg(target_os = "android")] { let fs = app.android_fs_async(); let file_picker = fs.file_picker(); let _ = file_picker .pick_dir( None, // no initial location hint true, // local only (no cloud storage) ) .await .map_err(|e| e.to_string()); } }
// javascript side ... // request file access permission if android window.addEventListener("DOMContentLoaded", async () => { try { await invoke("request_directory_access"); } catch (err) { console.error(err); } }); ...
pick_dir() is not a permission request. It opens Android's SAF folder picker.
Your code is probably not showing anything because you're calling it during DOMContentLoaded. On Android, these dialogs usually need to be triggered by a direct user action (button click, menu tap, etc).
Also, modern Android does not allow normal apps to get unrestricted access to /storage/emulated/0 anymore. With SAF, the user grants access only to the folder they select, not the whole storage.
So your Rust code is mostly fine. Try invoking it from a button click instead of automatically on startup.