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.
Asked
Active
Viewed 2,753 times
0
-
1There are tons of examples available online that show how to send emails via GMail using Indy components, for example: http://www.marcocantu.com/tips/oct06_gmail.html – Remy Lebeau Apr 22 '14 at 16:44
1 Answers
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;

wordermorr
- 315
- 1
- 4
- 13
-
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. – Remy Lebeau Mar 10 '15 at 18:27
-
Also, `Intent.EXTRA_EMAIL` is [documented](http://developer.android.com/reference/android/content/Intent.html#EXTRA_EMAIL) as expecting an **array** of string values, but you are passing it a **single** string instead. – Remy Lebeau Mar 10 '15 at 18:31