如何通过id获取原始资源文件名称?

时间:2022-01-27 16:49:06

I have .ogg files in res/raw, I have implemented a feature to save file to sdcard, and I want to set file name from original file.

我在res/raw文件中有.ogg文件,我实现了将文件保存到sdcard的功能,我想从原始文件中设置文件名。

3 个解决方案

#1


9  

It should work with resources.getResourceName( );

它应该与资源一起工作。getResourceName();

#2


8  

Use Resources.getResourceName(id) to get package:type/entryname, or Resources.getResourceEntryName(id) to get entry name (file name.)

使用Resources.getResourceName(id)获取包:type/entryname,或Resources.getResourceEntryName(id)以获取条目名称(文件名)。

#3


1  

If you're looking for the name from a resource ID, you can use Resources.getResourceName(). You can get the Resources object using Context.getResources().

如果要从资源ID中查找名称,可以使用Resources.getResourceName()。您可以使用Context.getResources()获取资源对象。

Personally, I'd rather store an array of strings in your strings.xml and map that to the resource IDs, but it depends on what you're really trying to accomplish.

就我个人而言,我宁愿将字符串数组存储在字符串中。xml并将其映射到资源id,但这取决于您真正想要实现的目标。

#1


9  

It should work with resources.getResourceName( );

它应该与资源一起工作。getResourceName();

#2


8  

Use Resources.getResourceName(id) to get package:type/entryname, or Resources.getResourceEntryName(id) to get entry name (file name.)

使用Resources.getResourceName(id)获取包:type/entryname,或Resources.getResourceEntryName(id)以获取条目名称(文件名)。

#3


1  

If you're looking for the name from a resource ID, you can use Resources.getResourceName(). You can get the Resources object using Context.getResources().

如果要从资源ID中查找名称,可以使用Resources.getResourceName()。您可以使用Context.getResources()获取资源对象。

Personally, I'd rather store an array of strings in your strings.xml and map that to the resource IDs, but it depends on what you're really trying to accomplish.

就我个人而言,我宁愿将字符串数组存储在字符串中。xml并将其映射到资源id,但这取决于您真正想要实现的目标。