title: Android: Saving a picture taken from an App and attaching it to email
body: <p>I am trying to create an App that takes a picture when a button is pressed and then attaches it to email when a send button is pressed. The code I have shows that the picture is attached to the email, but the attachment is not sent when I check the email I sent it to.The image is not saved in the SD card too.</p>
  
  <p>I call the initialize function in my onCreate() to initialize variable.Also I dont know where to put the SaveImage() function which has to save the image once it's taken. I put it in the onActivityResult() but does not work.
  Thanks in advance!</p>
  
  <pre><code>private void initialize() {
      // TODO Auto-generated method stub
      camera = (Button) findViewById(R.id.Picture);
      sendEmail = (Button) findViewById(R.id.SendMessage);
      iv = (ImageView) findViewById(R.id.ImageReturn);
      MessageTyped = (EditText) findViewById(R.id.MessageField);
      sendEmail.setOnClickListener(this);
      camera.setOnClickListener(this);
  
      pngDir = new File(Environment.getExternalStorageDirectory(),
      // Loose convention inferred from app examples
              "My Images");
  
      if (!pngDir.exists())
          pngDir.mkdirs();
  
  }
  
  @Override
  public void onClick(View v) {
  
      // TODO Auto-generated method stub
  
      switch (v.getId()) {
  
      case R.id.Picture:
          i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
          SaveImage();//&lt;------------------WHERE DOES THIS GO?
  
          startActivityForResult(i, cameraData);
  
          break;
  
      case R.id.SendMessage:
  
          EditTextToString();
  
          EmailIntent = new Intent(android.content.Intent.ACTION_SEND);
  
          EmailIntent.putExtra(Intent.EXTRA_EMAIL,
                  new String[] { "bipush.osti@gmail.com" });
          EmailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                  MessageToBeReceived);
  
          // EmailIntent.setType("message/rfc822");
          EmailIntent.setType("image/jpeg");
          EmailIntent.putExtra(Intent.EXTRA_STREAM, pngUri);
  
          startActivity(Intent.createChooser(EmailIntent,
                  "Choose an Email client :"));
          break;
  
      }
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      // TODO Auto-generated method stub
      super.onActivityResult(requestCode, resultCode, data);
      if (resultCode == RESULT_OK) {
          Bundle extras = data.getExtras();
          bmp = (Bitmap) extras.get("data");
          iv.setImageBitmap(bmp);
  
      }
  }
  
  private void EditTextToString() {
      MessageToBeReceived = MessageTyped.getText().toString();
  }
  
  private void SaveImage() {
  
      File pngFile = new File(pngDir, "jetsam.jpeg");
      // Save file encoded as PNG
      pngUri = Uri.fromFile(pngFile);
  
  }
  </code></pre>