0

I alredy see have two ways to send email programmatically.

1- calling intention to send email or 2- Javamail API

i m trying use this second way, (Sending Email in Android using JavaMail API without using the default/built-in app)

but now i need first take a picture and after send email with this picture and preferably send this image with size reduced.

can somone help me? use javamail api is the better solution? or how i can do that?

Community
  • 1
  • 1
rcorbellini
  • 1,307
  • 1
  • 21
  • 42
  • i guess you can just attach the image to the mail, that would do it – Goofy Jun 30 '14 at 13:14
  • 2
    [Take image](http://stackoverflow.com/questions/14421694/taking-pictures-with-camera-android-programmatically), [Send email with attachment](http://www.tutorialsbuzz.com/2014/02/send-mail-attachment-android-application.html), [Send email with attachment using javamail api](http://www.javatpoint.com/example-of-sending-attachment-with-email-using-java-mail-api) – MysticMagicϡ Jun 30 '14 at 13:18
  • so glad, thank you, i ll read all, i think this link ll be so helpfull. – rcorbellini Jun 30 '14 at 13:25

1 Answers1

2

Use this intent to take picture

                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                File f = new File(android.os.Environment.getExternalStorageDirectory(), AppInfo.getInstance().getCurrentLoginUserInfo().getId()+".jpg");
                intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
                intent.putExtra("return-data", true);
                startActivityForResult(intent, 1);

and on Your Activity Result.... Note Bitmap bitmap = getScaledBitmap(uri.getPath(), 200, true); 200 is your max image size.

if(requestCode == 1)
        {
String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
            final String imgPath = base + "/" +AppInfo.getInstance().getCurrentLoginUserInfo().getId()+".jpg";
            File file = new File(imgPath);
            if (file.exists()) 
            {
                Uri uri = Uri.fromFile(file);

                Log.d(TAG, "Image Uri path: " + uri.getPath());

                Bitmap bitmap = getScaledBitmap(uri.getPath(), 200, true);

            }}

This method ll return image bitmap after resizing it-

private Bitmap getScaledBitmap(String imagePath, float maxImageSize, boolean filter) {

    FileInputStream in;
    BufferedInputStream buf;

    try {
        in = new FileInputStream(imagePath);

        buf = new BufferedInputStream(in);
        Bitmap realImage = BitmapFactory.decodeStream(buf);


        float ratio = Math.min(
                (float) maxImageSize / realImage.getWidth(),
                (float) maxImageSize / realImage.getHeight());

        int width = Math.round((float) ratio * realImage.getWidth());
        int height = Math.round((float) ratio * realImage.getHeight());

        Bitmap newBitmap = Bitmap.createScaledBitmap(realImage, width, height, filter);
        return newBitmap;

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return null;
}

Now you have scaled bitmap image and you can attach it in mail -

read this -http://www.tutorialsbuzz.com/2014/02/send-mail-attachment-android-application.html

Hope this ll help you.

Rohit Goswami
  • 617
  • 5
  • 17