获取存储在RES /原始文件夹中的android .MP3文件的URI [英] Get URI of .mp3 file stored in res/raw folder in android

查看:150
本文介绍了获取存储在RES /原始文件夹中的android .MP3文件的URI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有存储在水库众多的.mp3文件/文件夹生

I have many .mp3 files stored in res/raw folder.

我使用下面的code得到.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

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");

当我选择任何邮件应用程序,例如。 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.

我要显示FILENAME.MP3

I want to display fileName.mp3

我怎样才能做到这一点?我失去了一些东西?

How can i do that? Am i missing something ?

有附加存储资源的.mp3文件中的任何其它方式/原料通过共享意向邮件。

Is there any other way to attach .mp3 file stored in res/raw to mail via Share Intent.

推荐答案

最后搜索了很多之后,我找到了解决办法。

Finally after searching a lot i found the solution.

如果你想获得任何资源的URI则有两种方式:

If you want to get any resource URI then there are two ways :

  1. 使用资源名称

  1. Using Resource Name

语法: android.resource:// [包装] / [RES类型] / [RES名称]

例如: Uri.parse(android.resource://com.my.package/drawable/icon);

使用资源ID

语法: android.resource:// [包装] / [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.

同样,你可以得到的资源/原材料文件夹的URI。

Similarly you can get URIs of res/raw folder.

在我的情况,我用1号的方式,即。使用资源名称

In my case i used 1st way ie. Using Resource Name

这篇关于获取存储在RES /原始文件夹中的android .MP3文件的URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆