Getting absolute path on android

2019-07-25 02:40发布

问题:

I've got c++ code in which I try to get a file from a directory on an android device. I've tried different ways to set the path which I pass to the fopen() function like: /Android/data/com.myapp/files/Blip.wav There actually is this file. But I guess that this is not a proper way to write a path. (The example was obtained by the java code )

getContext().getApplicationContext().getFilesDir().getPath() + "/Blip.wav"

回答1:

There actually is this file

Since I have never seen an Android device with an /Android directory, that is unlikely.

What would fit is if you are looking at /Android/data/com.myapp/files/Blip.wav in a desktop file manager, using a USB or similar connection. In that case, Android/data/com.myapp/files/Blip.wav is a relative path in external storage. Specifically, it maps to:

new File(getContext().getExternalFilesDir(), "Blip.wav")


回答2:

Try using this.

    File root=Environment.getExternalStorageDirectory();
    File file=new File(root,"/PersonData/Blip.wav");

Here personData is the name of folder