以下のコードを使用すると、アプリケーションから電子メールに問題なくファイルを添付できます (電子メール クライアントとして Gmail アプリケーションを使用している場合)。ただし、他の電子メール クライアントは、私が送信した添付ファイルを無視します。
これが私のコードです:
public static void sendEmail(Context context, String toAddress, String subject, String body, String attachmentPath) throws Exception{
try {
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", toAddress, null));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, body);
File file = new File(attachmentPath);
Uri uri = Uri.fromFile(file);
intent.putExtra(Intent.EXTRA_STREAM, uri);
context.startActivity(intent);
}
catch(Exception ex) {
ex.printStackTrace();
throw ex;
}
}
Gmail以外の電子メールクライアントが添付ファイルを認識して受け入れるようにインテントを設定する方法を知っている人はいますか?
ありがとうございました。