Rename URI file to share audio from raw folder

谁说我不能喝 提交于 2020-01-06 06:38:43

问题


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.

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.

I am using this code:

Intent share;

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

回答1:


The documentation for EXTRA_STREAM states that it is:

A content: URI holding a stream of data associated with the Intent, used with ACTION_SEND to supply the data being sent.

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.

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.

Also, do not use audio/*. Use the actual concrete MIME type of the content that you are sharing.



来源:https://stackoverflow.com/questions/49210768/rename-uri-file-to-share-audio-from-raw-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!