[英]Trying to share an mp3 with an intent but the file extension isn't included
Uri clipUri = Uri.parse("android.resource://com.packagename.community/raw/" + rawname);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, clipUri);
shareIntent.setType("audio/mpeg");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));
This code almost works, I can successfully send the clip to another app (dropbox for example) and everything is fine with the file except it lacks a .mp3 extension. 这段代码几乎可以正常工作,我可以将剪辑成功发送到另一个应用程序(例如,dropbox),并且除了没有.mp3扩展名之外,文件一切正常。
Welcome to StackOverflow! 欢迎来到StackOverflow! StackOverflow is for programming questions, and this is not a question.
StackOverflow用于编程问题,这不是问题。
I am going to interpret your non-question as: 我将把您的非问题解释为:
Why, when I use a
Uri
that does not have a file extension, is a file extension not magically added by file extension elves?为什么当我使用没有文件扩展名的
Uri
,文件扩展名精灵没有神奇地添加文件扩展名?
That's because Android lacks file extension elves. 这是因为Android缺少文件扩展名精灵。
If you want to have a file extension in your Uri
, you need to put one there. 如果要在
Uri
具有文件扩展名,则需要在其中放置一个文件扩展名。 And, since there is no syntax that I am aware of that will give an android.resource://
Uri
a file extension, your choices are: 并且,由于没有我知道的语法会给
android.resource://
Uri
提供文件扩展名,因此您可以选择:
Share a file, instead of a resource 共享文件而不是资源
Create a ContentProvider
that will serve up the resource via openFile
in response to some Uri
that does indeed have your desired file extension 创建一个
ContentProvider
来通过openFile
服务资源,以响应某些确实具有所需文件扩展名的Uri
Live without the file extension 没有文件扩展名的Live
Don't share the resource 不分享资源
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.