android-如何获取存储在原始文件夹中的mp3的路径 [英] android - how to get path of mp3 stored in raw folder
问题描述
After searching for solution, I have found from this link that it is possible to retrieve path like:
使用资源ID
语法:android.resource://[package]/[resource_id]
示例:Uri.parse("android.resource://com.my.package/" + R.raw.mp3filename);
这正是我想要的.问题是,我正在使用lolipop,但它不起作用.解析包/资源时,来自Uri.parse的路径将为null.还有其他写此方法的方法,因为在我的Song类中,我只能访问resourceId(R.raw.mp3filename).
Which is exactly what I want. Problem is that, I'm using lolipop, and it does not work. When the package/resource is parsed, path from Uri.parse will be null. Is there other way around to write this, since in my Song class, I have only access to resourceId (R.raw.mp3filename).
推荐答案
是否可以通过使用R.raw.mp3file获取文件路径
Is it possible to get file path by using R.raw.mp3file
否,因为它不是设备上的文件.它是开发计算机硬盘上的文件.在设备上,它只是APK文件中的一个条目.
No, because it is not a file on the device. It is a file on the hard drive of your development machine. On the device, it is merely an entry in an APK file.
要么:
-
执行您尝试做的其他任何不涉及文件路径的方式,或者
Do whatever you are trying to do some other way that does not involve a file path, or
在Resources
对象上使用openInputStream()
(您可以通过getResources()
从任何Context
中获得一个),并使用Java I/O将该资源的内容复制到本地文件中,例如内部存储
Use openInputStream()
on a Resources
object (you can get one from any Context
via getResources()
), and use Java I/O to copy the contents of that resource to a local file, such as on internal storage
这篇关于android-如何获取存储在原始文件夹中的mp3的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!