Android: How do I attach a temporary, generated image to an email?

前端 未结 3 1096
盖世英雄少女心
盖世英雄少女心 2020-11-29 02:50

I have a programmatically generated image that I want to send as an attachment via the ACTION_SEND and EXTRA_STREAM method.

But how do i do

3条回答
  •  离开以前
    2020-11-29 03:40

    tableLayout.buildDrawingCache();
            Bitmap test = Bitmap.createBitmap(tableLayout.getDrawingCache());
            tableLayout.destroyDrawingCache();
    
            Log.d("Image", test.toString());
    
            String path = Environment.getExternalStorageDirectory().toString(); 
            Log.d("Path", path);
            File file = new File(path,"mail_image.png");
            Uri pngUri = Uri.fromFile(file);
            Log.d("Real Image Path", pngUri.toString());
    
            Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.setType("image/png");
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "email to"); 
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject"); 
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "From My App"); 
                        emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, pngUri );
    
            startActivity(Intent.createChooser(emailIntent, "Send mail..."));
    

提交回复
热议问题