获取存储在 android res/raw 文件夹中的 .mp3 文件的 URI [英] Get URI of .mp3 file stored in res/raw folder in android
问题描述
我在 res/raw 文件夹中存储了许多 .mp3 文件.
I have many .mp3 files stored in res/raw folder.
我使用以下代码获取 .mp3 文件的 URI.
I am getting URI of .mp3 file using following code.
Uri.parse("android.resource:///com.my.android.sharesound/"+resId);
返回:android.resource:///com.my.android.sharesound/2130968609
现在我正在使用这个 URI 来创建 Share Intent
Now I am using this URI in creating Share Intent
shareIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("android.resource://com.my.android.sharesound/"+resId));
startActivity(Intent.createChooser(shareIntent,"Share Sound");
当我选择任何邮件应用程序时,例如.来自 Share Intent 的 Gmail 或 YahooMail,mp3 文件附加成功.但它显示2130968609(作为附件)
When i select any Mail application eg. Gmail or YahooMail from the Share Intent, the mp3 file attached successfully. But it shows that 2130968609(as an attachment)
我不想出现 resourceId(2130968609).
i dont want resourceId(2130968609) to appear.
我想显示文件名.mp3
I want to display fileName.mp3
我该怎么做?我错过了什么吗?
How can i do that? Am i missing something ?
或
有没有其他方法可以通过 Share Intent 将存储在 res/raw 中的 .mp3 文件附加到邮件中.
Is there any other way to attach .mp3 file stored in res/raw to mail via Share Intent.
推荐答案
终于找到了解决方案.
如果您想获取任何资源 URI,则有两种方法:
If you want to get any resource URI then there are two ways :
使用资源名称
Using Resource Name
语法:android.resource://[package]/[res type]/[res name]
示例:Uri.parse("android.resource://com.my.package/drawable/icon");
使用资源 ID
语法:android.resource://[package]/[resource_id]
示例:Uri.parse("android.resource://com.my.package/" + R.drawable.icon);
这是获取存储在可绘制文件夹中的任何图像文件的 URI 的示例.
This were the examples to get the URI of any image file stored in drawable folder.
同样,您可以获取 res/raw 文件夹的 URI.
Similarly you can get URIs of res/raw folder.
就我而言,我使用了第一种方式,即.使用资源名称
In my case i used 1st way ie. Using Resource Name
这篇关于获取存储在 android res/raw 文件夹中的 .mp3 文件的 URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!