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: "));
The documentation for
EXTRA_STREAM
states that it is:android.resource:
is notcontent:
. There is no requirement for anything that responds toACTION_SEND
to know what to do with anandroid.resource:
Uri
inEXTRA_STREAM
.Copy the resource to the local filesystem and use
FileProvider
, soFileProvider
can give you acontent:
Uri
to use withEXTRA_STREAM
. Or, write your ownContentProvider
that serves the content directly from your raw resource, and use acontent:
Uri
for your provider.Also, do not use
audio/*
. Use the actual concrete MIME type of the content that you are sharing.