我将如何以图片形式发送图片作为电子邮件的一部分

时间:2016-10-19 23:09:54

标签: java android email

嗨,大家为朋友制作一个简单的电子邮件应用程序..它会向他发送部分业务信息。但它有时也需要贴上照片。香港专业教育学院解决了相机的打开问题,并使用这段代码将图片保存到设备内存

 public class CameraDemoActivity extends Activity {
int TAKE_PHOTO_CODE = 0;
public static int count = 0;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Here, we are making a folder named picFolder to store
    // pics taken by the camera using this application.
    final String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/picFolder/";
    File newdir = new File(dir);
    newdir.mkdirs();

    Button capture = (Button) findViewById(R.id.btnCapture);
    capture.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            // Here, the counter will be incremented each time, and the
            // picture taken by camera will be stored as 1.jpg,2.jpg
            // and likewise.
            count++;
            String file = dir+count+".jpg";
            File newfile = new File(file);
            try {
                newfile.createNewFile();
            }
            catch (IOException e)
            {
            }

            Uri outputFileUri = Uri.fromFile(newfile);

            Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);

            startActivityForResult(cameraIntent, TAKE_PHOTO_CODE);
        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == TAKE_PHOTO_CODE && resultCode == RESULT_OK) {
        Log.d("CameraDemo", "Pic saved");
    }
}

}

我现在如何将此附加到应用中的电子邮件中?任何帮助总是感谢谢谢

1 个答案:

答案 0 :(得分:1)

我猜您将使用意图发送邮件,只需在构建您的意图时添加它:

intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));