0

Is it possible to share through Intent some audio files to other apps like telegram, google drive, whatsapp ? My files are being downloaded and kept into my app private folder, like: /data/user/0/myPackage/app_NameOfFolder/file.mp3

I wrote this simple method:

    public void sendSound(String fileToSend){
    try{

        Log.d(TAG,"Sending: " + fileToSend);
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        Uri audioUri = Uri.parse(fileToSend);
        sharingIntent.setType("audio/*");
        sharingIntent.putExtra(Intent.EXTRA_STREAM, audioUri);
        startActivity(Intent.createChooser(sharingIntent, "Share"));

    }catch (Exception e){
        Log.d("TAG",e.getMessage());
        Log.d("TAG",e.toString());
    }

}

But i'm not able to share it, getting error:"unable to share please retry" If i move the file into a public directory, like: Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath() +"/file.mp3";

It works, so i think it's something related to permission, so this is my manifest:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />

Dunno what am i doing wrong tho.

Vesco
  • 138
  • 2
  • 15
  • Sorry not possible – M D Aug 29 '16 at 13:27
  • You can try to share your files **as generic files** by attaching them to an eMail intent. By using an `intent chooser`, you will be able to choose which app to use to send it out. – Phantômaxx Aug 29 '16 at 13:30

1 Answers1

5

Third-party apps have no rights to your portion of internal storage.

Most likely, you can use FileProvider to make this content available to other apps, at least if your file is somewhere under getFilesDir() or getCacheDir().

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • All right i will give it a try, thank you for trying to point me out to a solution. – Vesco Aug 29 '16 at 13:34
  • well I'm trying similar [**here**](https://stackoverflow.com/q/46789824/2624806). Any suggestion what I'm missing ? – CoDe Oct 17 '17 at 12:13