Send email using bitmap object as android app?

I want to send a bitmap as an attachment in the mail. The image is not saved on the SDCARD or anywhere on the device. A bitmap object is created at runtime and should be sent as an attachment.

+8
android email attachment
source share
2 answers

Then you have to save the Bitmap to the SDCard and then attach it to the email (I think you know how to do this ).

Why is it necessary to save it to an SDCard? This is because the email application will have to read the file that it will be attached; therefore, you must pass the path and file name to the email client. Like any other application, the email client can only access files stored in its own personal directory or SDCard.

+9
source share
/* Return Drawable Object from Specified imageUrl In Web @imageUrl : image Url in Web */ try { /// Getting image from Web InputStream is = (InputStream) new URL(imageUrl).getContent(); // storing image from stream drawable = Drawable.createFromStream(is, "srcName"); is.close(); // converting drawable object to Bitmap to store in content providers of Media Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); // Store image in Devise database to send image to mail String path = Images.Media.insertImage(getContentResolver(), bitmap,"title", null); Uri screenshotUri = Uri.parse(path); final Intent emailIntent1 = new Intent( android.content.Intent.ACTION_SEND); emailIntent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); emailIntent1.putExtra(Intent.EXTRA_STREAM, screenshotUri); emailIntent1.setType("image/png"); startActivity(Intent.createChooser(emailIntent1, "Send email using")); } catch(Exception e) { } 
+4
source share

Source: https://habr.com/ru/post/651411/


All Articles