procedure TForm1.Button1Click(Sender: TObject);
var
sl: TStringList;
sFileName: string;
begin
sFileName := Androidapi.IOUtils.getExternalFilesDir + PathDelim + 'Test.txt';
sl := TStringList.Create;
try
sl.Add('TestContent');
sl.SaveToFile(sFileName);
finally
FreeAndNil(sl); // Arc eigentlich unnötig
end;
CreateEmail('aaaaa@bbbbb.com', 'TestFromDelphi', 'Dödeldiedeidiedödeldiemöp','Test.txt');
end;
Learn how to send mail with attachments with your Delphi XE5 Android Application.
Update: Link appears to be down. Try this StackOverflow answer.
procedure TForm1.CreateEmail(const Recipient, Subject, Content, Attachment: string);
var
JRecipient: TJavaObjectArray<JString>;
Intent: JIntent;
Uri: Jnet_Uri;
AttachmentFile: JFile;
begin
JRecipient := TJavaObjectArray<JString>.Create(1);
JRecipient.Items[0] := StringToJString(Recipient);
Intent := TJIntent.Create;
Intent.setAction(TJIntent.JavaClass.ACTION_SEND);
Intent.setFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK);
Intent.putExtra(TJIntent.JavaClass.EXTRA_EMAIL, JRecipient);
Intent.putExtra(TJIntent.JavaClass.EXTRA_SUBJECT, StringToJString(Subject));
Intent.putExtra(TJIntent.JavaClass.EXTRA_TEXT, StringToJString(Content));
if Attachment <> '' then
begin
AttachmentFile := TJFile.JavaClass.init(StringToJString(Attachment));
Uri := TJnet_Uri.JavaClass.fromFile(AttachmentFile);
Intent.putExtra(TJIntent.JavaClass.EXTRA_STREAM, TJParcelable.Wrap((Uri as ILocalObject).GetObjectID));
end;
Intent.setType(StringToJString('vnd.android.cursor.dir/email'));
SharedActivity.startActivity(Intent);
end;