7

このコードを使用してファイルを添付しています。

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SENDTO);
String uriText;
Uri file = Uri.fromFile(new File(path));
uriText = "mailto:" + 
              "?subject=the subject" + 
              "&body=the body of the message"+
              "&attachment="+file;
uriText = uriText.replace(" ", "%20");
Uri uri = Uri.parse(uriText);
emailIntent.setData(uri);
startActivity(Intent.createChooser(emailIntent, "Send mail..."));

(これpathは "/sdcard/test.jpg" のようなものACTION_SENDTOで、セレクターでメール アプリを表示したいだけなので使用したことに注意してください。)

インテントは電子メール アプリケーションのリストを提供しますが、添付ファイルは電子メールまたは Gmail に表示されません。添付ファイルを表示するにはどうすればよいですか?

4

4 に答える 4

0

この方法は私にとってはうまくいきます:

public static void sendEmailWithImages(Context context, String emailTo, String emailCC, String subject, String emailText, String type, List<String> filePaths) {
    //need to "send multiple" to get more than one attachment
    final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
    emailIntent.setType(type);
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{emailTo});
    emailIntent.putExtra(android.content.Intent.EXTRA_CC, new String[]{emailCC});
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailText);
    //has to be an ArrayList
    ArrayList<Uri> uris = new ArrayList<Uri>();
    //convert from paths to Android friendly Parcelable Uri's
    if(filePaths != null) {
        for (String file : filePaths) {
            File fileIn = new File(file);
            Uri u = Uri.fromFile(fileIn);
            uris.add(u);
        }
        emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    }
    try {
        context.startActivity(Intent.createChooser(emailIntent, context.getString(R.string.send_email_using_message)));
    }catch (ActivityNotFoundException e) {
        //TODO
    }
}
于 2012-10-05T07:58:01.423 に答える