重命名URI文件以共享原始文件夹中的音频 [英] Rename URI file to share audio from raw folder
问题描述
我正在尝试创建一个共享应用程序原始"文件夹中的子项的应用程序,但我没有得到.该文件是共享的,但没有.mp3扩展名.我听不到Windows Media Player的声音,但是我手动输入了.mp3扩展名.有人知道我该如何自动获取.mp3扩展名吗?将URI转换/重命名为mp3文件.
I'm trying to make an application with sharing of children that are inside the "raw" folder of the application, but I'm not getting it. The file is shared but does not have an .mp3 extension. I was not able to hear Windows Media Player, but I put a .mp3 extension manually. Does anybody have any idea how I do it to get .mp3 extension automatically? Transform / rename a URI into mp3 file.
歌曲的名称来自文件中注册的名称,我相信如果可以重命名,最后添加.mp3可能会起作用.但是我无法重命名.
The name of the song comes as it is registered in the file, I believe that if it was possible to rename adding the .mp3 in the end may work. But I'm not able to rename.
我正在使用以下代码:
意图分享;
Uri uri = Uri.parse("android.resource://"+this.getPackageName()+"/raw/name_musica");
share = new Intent(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_STREAM, uri); share.setType("audio/*");
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(share, "Enviar via: "));
推荐答案
The documentation for EXTRA_STREAM
states that it is:
内容:包含与Intent关联的数据流的URI,与ACTION_SEND一起使用以提供要发送的数据.
A content: URI holding a stream of data associated with the Intent, used with ACTION_SEND to supply the data being sent.
android.resource:
不是content:
.不需要任何响应ACTION_SEND
的东西来知道如何处理EXTRA_STREAM
中的android.resource:
Uri
.
android.resource:
is not content:
. There is no requirement for anything that responds to ACTION_SEND
to know what to do with an android.resource:
Uri
in EXTRA_STREAM
.
将资源复制到本地文件系统并使用FileProvider
,因此FileProvider
可以为您提供content:
Uri
与EXTRA_STREAM
一起使用.或者,编写您自己的ContentProvider
,直接从您的原始资源中提供内容,并为提供者使用content:
Uri
.
Copy the resource to the local filesystem and use FileProvider
, so FileProvider
can give you a content:
Uri
to use with EXTRA_STREAM
. Or, write your own ContentProvider
that serves the content directly from your raw resource, and use a content:
Uri
for your provider.
此外,请勿使用audio/*
.使用要共享的内容的实际具体MIME类型.
Also, do not use audio/*
. Use the actual concrete MIME type of the content that you are sharing.
这篇关于重命名URI文件以共享原始文件夹中的音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!