0

Im trying to implement a share button to send a file that mi app creates.

in my Manifest:

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        tools:ignore="ScopedStorage" /> #Tried with and whithout ScopedStorage

My code:

    public  void buttonShareFile(View view) {

        File file = new File(stringFile);

        if(!file.exists()) {
            Toast.makeText(this, "No file!", Toast.LENGTH_LONG).show();
            return;
        }

        Intent intentShare = new Intent(Intent.ACTION_SEND);
        intentShare.setType("text/csv");

        intentShare.putExtra(Intent.EXTRA_STREAM, Uri.parse(("file://"+file)));

        startActivity(Intent.createChooser(intentShare, "Share the file...."));

Send intent is created and looks fine for Whatsapp or email, but when the receiver is selected an error occurs with this message in LOGCAT:

E/MediaProvider: Permission to access file: /storage/emulated/0/Download/Export.csv is denied

Thanks in advance!

0 Answers0