The <img> tag will not work. To send an image as an attachment, you must save it to the SD card.
You need to add
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
to your AndroidManifest.xml.
To save the image, do this (in the background thread!):
try { File rootSdDirectory = Environment.getExternalStorageDirectory(); File pictureFile = new File(rootSdDirectory, "attachment.jpg"); if (pictureFile.exists()) { pictureFile.delete(); } pictureFile.createNewFile(); FileOutputStream fos = new FileOutputStream(pictureFile); URL url = new URL("http://your_image_server/dummy.jpg"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setDoOutput(true); connection.connect(); InputStream in = connection.getInputStream(); byte[] buffer = new byte[1024]; int size = 0; while ((size = in.read(buffer)) > 0) { fos.write(buffer, 0, size); } fos.close(); } catch (Exception e) { e.printStackTrace(); return null; }
After the image has been saved, get its Uri and send it to the intent (in the main stream):
Uri pictureUri = Uri.fromFile(pictureFile); emailIntent.putExtra(Intent.EXTRA_STREAM, pictureUri);
Hope this helps :)
source share