Getting absolute path on android

一笑奈何 提交于 2019-12-13 17:32:23

问题


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



来源:https://stackoverflow.com/questions/41283619/getting-absolute-path-on-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!