我需要创建文件选择器的帮助,该选择器获取被选为Uri的音频文件的路径。
这是我当前用作文件选择器的内容:
public void selectedAudio() {
Intent intent = new Intent();
intent.setType("audio/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(Intent.createChooser(intent, "Choose Sound File"), 1);
}
但是我不知道如何获取所选文件的路径。
最佳答案
在onActivityResult()方法中,调用传递的Intent的getData()方法,然后调用getPath:
String filePath = data.getData().getPath();
关于android - 从文件选择器获取音频文件Uri,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19073110/