Image preview in email Intent not showing when loaded from Assets Folder

后端 未结 1 447
北恋
北恋 2021-01-28 11:07

I have something like the following code:

public void shareImageInEmail(String imageUri){
   Intent emailIntent = new Intent(Intent.ACTION_SEND)         


        
相关标签:
1条回答
  • 2021-01-28 11:32

    A simple solution will be to copy all contents in Assets to Sdcard and pass 'Sdcard path Uri' as EXTRA_STREAM to Email.

    Sample Code:

    public void shareImageInEmail(String imageUri){
           Intent emailIntent = new Intent(Intent.ACTION_SEND);        
           emailIntent.setType("message/rfc822");
    
           emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
           emailIntent.putExtra(Intent.EXTRA_TEXT, "Some text");
    
           Log.v(TAG, "imageUri, file://" + imageUri);
           emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + imageUri));
           startActivity(emailIntent);
    }
    

    Copy all assets to SDCard (Refer: How to copy files from 'assets' folder to sdcard?)

    new File(Environment.getExternalStorageDirectory(), filename); //Store in Sdcard
    

    And finally call shareImageInEmail as follows,

    shareImageInEmail(Environment.getExternalStorageDirectory() + "/Image.png");//assets[0]);
    
    0 讨论(0)
提交回复
热议问题