Vesco
Vesco

Reputation: 138

Android share app private files

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.

Upvotes: 0

Views: 1916

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006644

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().

Upvotes: 5

Related Questions