我有一个应用程序可以让用户从 sdcard 中选择音乐文件。要启动我正在使用的选择器意图
Intent intent = new Intent();
intent.setType("audio/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(
Intent.createChooser(intent, "Complete action using"), 0);
但是根据用户选择的方法,我得到不同的绝对路径。如果用户使用 ES 文件资源管理器,那么我会得到/sdcard/Music/song.mp3
,但如果用户使用一些音乐应用程序,那么我会得到/storage/sdcard0/Music/song.mp3
. 它非常令人困惑,我的应用程序要求我知道一个最终的基本路径。
Environment.getExternalStorageDirectory()
返回/storage/sdcard0/
。任何帮助,将不胜感激。
注意:在这两种情况下
Uri uri = Uri.parse(new File(soundPath).getAbsolutePath());
mPlayer = MediaPlayer.create(this, uri);
工作正常。