Home » Android » Only google drive recognizes audio file when sharing

Only google drive recognizes audio file when sharing

Posted by: admin November 1, 2017 Leave a comment

Questions:

With this snippet of code I share an audio:

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("audio/mp3");
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(
                "android.resource://"+getPackageName()+"/raw/"+
                getResources().getResourceEntryName(audiosRage[position])));
startActivity(Intent.createChooser(sharingIntent, "Compartilhar via"));

They are contained in the ‘raw’ folder. I can send them through whatsapp, but in a format without extension that does not run. On the other hand, when saved on google drive, it recognizes it as a music file and runs, though it does not have extension. All audios in the raw folder are in .mp3 format

Answers:

The documentation for EXTRA_STREAM says that you should use a Uri with a content scheme. So, for example, you could use FileProvider to serve up some local file that contains your audio.