Android - not able to attach a file in email

前端 未结 7 528
孤城傲影
孤城傲影 2020-12-03 11:48

By default, files saved to the internal storage are private to your application and other applications cannot access them (nor can the user).

I am able to see the fi

相关标签:
7条回答
  • 2020-12-03 12:27

    I was facing the same issue and following worked for me.

    First send Broadcast to notify device that file is created / mounted.

    For example:

    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,Uri.parse("file://"+storagePath)));
    

    Then use code to send mail with attachment.

    Intent email = new Intent(Intent.ACTION_SEND);
    email.putExtra(Intent.EXTRA_EMAIL,  "Receiver Email Address" );
    email.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    email.putExtra(Intent.EXTRA_SUBJECT, "Subject");
    email.putExtra(Intent.EXTRA_TEXT,"Email Text");
    
    //Mime type of the attachment (or) u can use sendIntent.setType("*/*")
    //email.setType("text/plain");
    email.setType("application/YourMimeType");
    
    //Full Path to the attachment
    email.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+storagePath));
    try
    {
        startActivity(Intent.createChooser(email, "Send Message..."));
    }
    catch (android.content.ActivityNotFoundException ex) 
    {
    
    }
    
    0 讨论(0)
提交回复
热议问题