1

I want to send screenshot via email. Below is how i manage to take screenshot and save in directory. What i want is to not save but send directly. How can i achieve it?

public Bitmap takeScreenshot() {

    View rootView = getWindow().getDecorView().findViewById(R.id.relative);
    rootView.setDrawingCacheEnabled(true);

    return rootView.getDrawingCache();

}

public void saveBitmap(Bitmap bitmap) {

    String root = Environment.getExternalStorageDirectory().toString();
    File newDir = new File(root + "/MapCards");
    newDir.mkdirs();
    Random gen = new Random();
    int n = 10000;
    n = gen.nextInt(n);
    String fotoname = "MapCard-" + n + ".jpg";
    File file = new File(newDir, fotoname);
    if (file.exists())
        file.delete();
    try {
        FileOutputStream fos = new FileOutputStream(file);
        bitmap.compress(CompressFormat.JPEG, 100, fos);
        fos.flush();
        fos.close();
        Toast.makeText(getApplicationContext(),
                "Saved in folder: 'MapCards'", Toast.LENGTH_SHORT).show();

    } catch (FileNotFoundException e) {
        Log.e("GREC", e.getMessage(), e);
    } catch (IOException e) {
        Log.e("GREC", e.getMessage(), e);
    }

}

Maybe i need to add something like below, after i take the screenshot but i am not sure how to configure it together.

public void send() {
    String temp = getIntent().getStringExtra("picture_path");
    URI = Uri.parse("file://" + temp);
    final Intent emailIntent = new Intent(
            android.content.Intent.ACTION_SEND);
    emailIntent.setType("image/jpeg");
    if (URI != null) {
        emailIntent.putExtra(Intent.EXTRA_STREAM, URI);
    }
    this.startActivity(Intent.createChooser(emailIntent,
            "Send email using.."));

}

Thank you for help.

Umit Kaya
  • 5,771
  • 3
  • 38
  • 52
  • possible duplicate of [Android\Intent: Send an email with attachment](http://stackoverflow.com/questions/6078099/android-intent-send-an-email-with-attachment) – rupesh jain Aug 12 '14 at 05:13
  • Try this may it helps you. URI = Uri.parse("file:/" + temp); – Pradeep Kumar Aug 12 '14 at 05:36
  • Check Here http://stackoverflow.com/questions/587917/trying-to-attach-a-file-from-sd-card-to-email – Pradeep Kumar Aug 12 '14 at 05:37
  • @PradeepYaduvanshy this is to attach from gallery as i understood. but i want to send the image without accessing gallery. certain image on screen. thanks btw. – Umit Kaya Aug 12 '14 at 06:24

1 Answers1

0

Its my working code.Please try it.

final File file = getTempPictureFile();
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType(HTTP.PLAIN_TEXT_TYPE);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, Constants.EMAIL_SUBJECT);
emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(Constants.EMAIL_BODY_MSG));
if(file != null)
{
     emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
}
startActivity(Intent.createChooser(emailIntent, Constants.CHOOSE_EMAIL_CLIENT));
Uday Sravan K
  • 1,305
  • 12
  • 18
  • Its will just return your screen shot image file. add it to your code. picture_path must be full path of your image file from sdcard. getTempPictureFile(){ String temp = getIntent().getStringExtra("picture_path");return new File(temp); } – Uday Sravan K Aug 12 '14 at 08:38