Skip to content

How can I get the path of Android internal storage in Dioxus@0.6? #3475

Answered by LaurentMazare
imbolc asked this question in Q&A
Discussion options

You must be logged in to vote

I came across a similar issue today (finding some local directory where to store some persistent files) and came up with something like this. Disclaimer: I'm a total newbie when it comes to android development so I don't have much of a clue whether this is reasonable or not and how it compares to using internal_data_path.

fn get_cache_dir() -> Result<String> {
    let ctx = ndk_context::android_context();
    let vm = unsafe { jni::JavaVM::from_raw(ctx.vm().cast()) }?;
    let mut env = vm.attach_current_thread()?;
    let ctx = unsafe { jni::objects::JObject::from_raw(ctx.context().cast()) };
    let cache_dir = env
        .call_method(ctx, "getFilesDir", "()Ljava/io/File;", &[])?
        

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
2 replies
@imbolc
Comment options

imbolc Jan 1, 2025
Author Sponsor

@jkelleyrtp
Comment options

Answer selected by imbolc
Comment options

You must be logged in to vote
3 replies
@imbolc
Comment options

imbolc Jan 3, 2025
Author Sponsor

@sehnryr
Comment options

@imbolc
Comment options

imbolc Jan 3, 2025
Author Sponsor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants