Question

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.

Was it helpful?

Solution

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top