0

我正在尝试制作一个应用程序,它可以让我拍摄一些照片,然后通过电子邮件将它们发送给某人。拍照和发送电子邮件确实有效,但如何将照片附加到电子邮件中?

这是我用来在意图一中拍照的代码:

public void maak_foto(View view) {

    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

    File pictureFileDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    File FileDir = new File(pictureFileDir, "offerte_fotos");

    try {
        FileDir.mkdirs();
    }finally {

    }

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyymmddhhmmss", Locale.getDefault());
    String date = dateFormat.format(new Date());
    String photoFile = "OfferteFoto_" + date + ".jpg";

    String filename = pictureFileDir.getPath() + File.separator + photoFile;

    File photo = new File(filename);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
    imageUri = Uri.fromFile(photo);
    startActivityForResult(intent, TAKE_PICTURE);
}


@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case TAKE_PICTURE:
        if (resultCode == Activity.RESULT_OK) {
            Uri selectedImage = imageUri;
            getContentResolver().notifyChange(selectedImage, null);
            ContentResolver cr = getContentResolver();



            try {
                bitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, selectedImage);


                bitmap.recycle();
                Toast.makeText(this, selectedImage.toString(), Toast.LENGTH_LONG).show(); 
                Log.i("IMAGE_PATH", selectedImage.toString());
            } catch (Exception e) {
                Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT).show();
                Log.e("Camera", e.toString());
            }
        }
    }
}

这是我用来以另一种意图发送电子邮件的代码。(点击下一步时)

        String to = "email adres goes here";
    String verkoopmail[] = { to } ;
    String message = "Hallo verkoop, "
            + '\n' + "Dhr./Mevr. " + contactpersoon + " van " + bedrijfsnaam + " wil graag een offerte ontvangen voor een " + soortbouw + "." 
            + '\n' + "De algemeene contact gegevens zijn:"
            + '\n' + "Adres: " + adres
            + '\n' + "Telefoon nummer: " + telefoon
            + '\n' + "Email adres: " + email;


    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
    emailIntent.setType("image/jpeg"); //text/plain
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, verkoopmail);
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Offerte aanvraag");
    emailIntent.putParcelableArrayListExtra(android.content.Intent.EXTRA_STREAM, uris);

    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
    startActivity(emailIntent);

我不知道如何从拍照意图获取 URI 到发送电子邮件意图。我可能在某处做错了什么。

希望有人可以提供帮助。

4

0 回答 0