Gmail 5.0 app fails with “Permission denied for the attachment” when it receives ACTION_SEND intent

后端 未结 9 1220
感动是毒
感动是毒 2020-11-27 18:35

My app creates mails with attachments, and uses an intent with Intent.ACTION_SEND to launch a mail app.

It works with all the mail apps I tested with, e

9条回答
  •  悲哀的现实
    2020-11-27 19:22

    Use getExternalCacheDir() with File.createTempFile.

    Use the following to create a temporary file in the external cache directory:

    File tempFile = File.createTempFile("fileName", ".txt", context.getExternalCacheDir());
    

    Then copy your original file's content to tempFile,

    FileWriter fw = new FileWriter(tempFile);
    
    FileReader fr = new FileReader(Data.ERR_BAK_FILE);
    int c = fr.read();
    while (c != -1) {
        fw.write(c);
        c = fr.read();
    }
    fr.close();
    
    fw.flush();
    fw.close();
    

    now put your file to intent,

    emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(tempFile));
    

提交回复
热议问题