0

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

1 Answer 1

2

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;
2
  • This code is misusing the Activity.getExternalFilesDir() method. Assuming Attachment is a full path to the actual file being attached, use AttachmentFile := 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.