How do I send WebView display page content to email body in android? [closed]

Insted of taking the webview content as html, take a snapshot of your webview and attach the image file in your mail.

Taking Web view as screen shot (Image)

// image naming and path  to include sd card  appending name you choose for file
String mPath = Environment.getExternalStorageDirectory().toString() + "" + ACCUWX.IMAGE_APPEND;   
// create bitmap screen capture
Bitmap bitmap;
View v1 = mWebview.getRootView(); // take the view from your webview
bitmap = Bitmap.createBitmap(v1.getDrawingCache());

OutputStream fout = null;
imageFile = new File(mPath);

try {
  fout = new FileOutputStream(imageFile);
  bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);

} catch (FileNotFoundException e) {
   // TODO Auto-generated catch block
} catch (IOException e) {
  // TODO Auto-generated catch block

sending the attachment through email

Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {"[email protected]"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "subject here");
emailIntent.putExtra(Intent.EXTRA_TEXT, "body text");
File root = Environment.getExternalStorageDirectory();
String pathToMyAttachedFile="temp/attachement.xml";
File file = new File(root, pathToMyAttachedFile);
if (!file.exists() || !file.canRead()) {
Uri uri = Uri.fromFile(file);
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(emailIntent, "Pick an Email provider")); 

You also need to give the user permission via a manifest file like below

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  <uses-permission android:name="android.permission.INTERNET" />

Leave a Comment