It's simple: i'm trying to create an email using the gmail app for android, just like when you share something using gmail. I have no idea how to do it.
1 Answer
Found it:
procedure TfrmSendMail.CreateEmail(const Recipient, Subject, Content,
Attachment, Attachment2: string);
var
Intent: JIntent;
Uri: Jnet_Uri;
AttachmentFile: JFile;
begin
Intent := TJIntent.Create;
Intent.setAction(TJIntent.JavaClass.ACTION_SEND_MULTIPLE);
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;
-
This code is misusing the
Activity.getExternalFilesDir()
method. AssumingAttachment
is a full path to the actual file being attached, useAttachmentFile := TJFile.JavaClass.init(StringToJString(Attachment))
instead. Mar 10, 2015 at 18:27 -
Also,
Intent.EXTRA_EMAIL
is documented as expecting an array of string values, but you are passing it a single string instead. Mar 10, 2015 at 18:31