How to ask Android for the right to access user files

7 hours ago 3
ARTICLE AD BOX

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); } }); ...
Read Entire Article