Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

audio - Get URI of .mp3 file stored in res/raw folder in android

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

I am getting URI of .mp3 file using following code.

Uri.parse("android.resource:///com.my.android.sharesound/"+resId);

This returns : android.resource:///com.my.android.sharesound/2130968609

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

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)

i dont want resourceId(2130968609) to appear.

I want to display fileName.mp3

How can i do that? Am i missing something ?

OR

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

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Finally after searching a lot i found the solution.

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

  1. Using Resource Name

    Syntax : android.resource://[package]/[res type]/[res name]

    Example : Uri.parse("android.resource://com.my.package/drawable/icon");

  2. Using Resource Id

    Syntax : android.resource://[package]/[resource_id]

    Example : Uri.parse("android.resource://com.my.package/" + R.drawable.icon);

This were the examples to get the URI of any image file stored in drawable folder.

Similarly you can get URIs of res/raw folder.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...