How to send email with attachment using default Android email app – Delphi XE7

  

Using code below which I found on another post, the email appears ready to send with the attachment, but when email is received, there is no attachment. Also, the email address has to be manually entered, it is not populated by the CreateEmail statement. I am sending from a gmail account. Anyone help please?

procedure TForm1.CreateEmail(const Recipient, Subject, Content,
Attachment: string);
var
Intent: JIntent;
Uri: Jnet_Uri;
AttachmentFile: JFile;
begin
Intent := TJIntent.Create;
Intent.setAction(TJIntent.JavaClass.ACTION_SEND);
Intent.setFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK);
Intent.putExtra(TJIntent.JavaClass.EXTRA_EMAIL, StringToJString(Recipient));
Intent.putExtra(TJIntent.JavaClass.EXTRA_SUBJECT, StringToJString(Subject));
Intent.putExtra(TJIntent.JavaClass.EXTRA_TEXT, StringToJString(Content));
AttachmentFile := SharedActivity.getExternalFilesDir
(StringToJString(Attachment));

Uri := TJnet_Uri.JavaClass.fromFile(AttachmentFile);

Intent.putExtra(TJIntent.JavaClass.EXTRA_STREAM,
TJParcelable.Wrap((Uri as ILocalObject).GetObjectID));

Intent.setType(StringToJString(‘vnd.android.cursor.dir/email’));

SharedActivity.startActivity(Intent);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
CreateEmail(‘xxx@shaw.ca’, ‘Test Results’, Memo1.Lines.text,’/sdcard/Download/Demo.pdf’);
end;

Comments are closed.