Showing posts with label Email intent. Show all posts
Showing posts with label Email intent. Show all posts

Sunday, April 17, 2011

Share via Email Intent in Android (Image attachment)

Here is the code for Sharing via Email functionality, and you can attach image with the email.

//cacheDir is file path to your application's cache directory where image is located.
//You can provide your own file object by replacing object f.
File cacheDir = new File(android.os.Environment.getExternalStorageDirectory(), getString(getApplicationInfo().labelRes));
File f = new File(cacheDir, "image_name.jpg");


Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("image/jpeg"); intent.putExtra(Intent.EXTRA_TEXT, "Email body over here"); intent.putExtra(Intent.EXTRA_SUBJECT, "Email subject over here"); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f)); startActivity(Intent.createChooser(intent, "Share via:"));