我使用了ACTION_GET_CONTENT Intent来让用户从他的库中选择一首歌曲,然后将它作为URI返回到onActivityResult()
方法中。如何从ACTION_GET_CONTENT获取的URI获取文件名意图?
我需要获取歌曲的名称。
我试着用:
Uri song; //got from onActivityResult
String songName = song.getLastPathSegment();
,并用:
Uri song; //got from onActivityResult
File file = new File(song.getPath());
String songName = file.getName();
在两种情况下
songName
字符串看起来像这样
:
// audio:9980
,而我希望是这样的:
// Walk on the wild side.mp3
我在做什么错?
我其实在问题中解释错了。我现在将编辑它。我知道我没有使用文件,但使用Uri,我知道它们之间的区别。你可以在你得到这个名字的地方张贴这段代码吗?感谢您的快速回答 – Daniele
@Daniele:请参阅[示例应用程序中的这些行](https://github.com/commonsguy/cw-omnibus/blob/v8.5/Documents/Consumer/app/src/main/ java/com/commonsware/android/documents/consumer/ConsumerFragment.java#L91-L142)我使用'CursorLoader'来检索'OpenableColumns'。 – CommonsWare