Sending Multiple Attachments firemonkey

  

I’m trying send a email with multiple attachments, but, in Android SDK most recent, was changed the method to send files, and most existing tutorials is about the older SDK version …

I obtained send the email with only one attachment, but not with multiple…

I try using the same method of 1 attachment but using it twice. Not works, the delphi catch only the last Intent.putExtra.

What I’m making wrong ?

(Utilizing only the Android Plataform)

procedure TF_inicio.Rec_exportClick(Sender: TObject);
var
sfilename: string;

AttachmentFile1: JFile;
AttachmentFile2: JFile;
AttachmentFile3: JFile;

Intent: JIntent;
AddressesTo, Anexos: TJavaObjectArray<JString>;
LList: TStringDynArray;
I: Integer;
LSearchOption: TSearchOption;
// AddressesCC, AddressesBCC: TJavaObjectArray<JString>;
begin
LSearchOption := TSearchOption.soTopDirectoryOnly;
LList := TDirectory.GetFiles(path, ‘*.csv’, LSearchOption);

Intent := TJIntent.Create;
Intent.setAction(TJIntent.JavaClass.ACTION_SENDTO);
Intent.setData(TJnet_Uri.JavaClass.parse(StringToJString(‘mailto:’)));
AddressesTo := TJavaObjectArray<JString>.Create(1); // Enviar para:
AddressesTo.Items[0] := StringToJString(‘MyEmail@gmail.com’);
Intent.putExtra(TJIntent.JavaClass.EXTRA_EMAIL, AddressesTo);
Intent.putExtra(TJIntent.JavaClass.EXTRA_SUBJECT,
StringToJString(F_inicio.placa_veiculo + ‘ – ‘ +
FormatDateTime(‘dd/mm/yyyy hh:MM’, NOW)));
Intent.putExtra(TJIntent.JavaClass.EXTRA_TEXT,
StringToJString(‘Email automático’ + sLineBreak + ”));

if Length(LList) = 1 then
AttachmentFile1 := TJFile.JavaClass.init(StringToJString(LList[1]));

if Length(LList) = 2 then
AttachmentFile2 := TJFile.JavaClass.init(StringToJString(LList[2]));

if Length(LList) = 3 then
AttachmentFile3 := TJFile.JavaClass.init(StringToJString(LList[3]));

if Length(LList) >= 1 then
begin
AttachmentFile1 := TJFile.JavaClass.init(StringToJString(LList[1]));
Intent.putExtra(TJIntent.JavaClass.EXTRA_STREAM,
TJParcelable.Wrap((TJnet_Uri.JavaClass.fromFile(AttachmentFile1)
as ILocalObject).GetObjectID));
end;

if Length(LList) >= 2 then
begin
AttachmentFile2 := TJFile.JavaClass.init(StringToJString(LList[2]));
Intent.putExtra(TJIntent.JavaClass.EXTRA_STREAM,
TJParcelable.Wrap((TJnet_Uri.JavaClass.fromFile(AttachmentFile2)
as ILocalObject).GetObjectID));
end;

if Length(LList) >= 3 then
begin
AttachmentFile3 := TJFile.JavaClass.init(StringToJString(LList[3]));
Intent.putExtra(TJIntent.JavaClass.EXTRA_STREAM,
TJParcelable.Wrap((TJnet_Uri.JavaClass.fromFile(AttachmentFile3)
as ILocalObject).GetObjectID));
end;

SharedActivity.startActivity(Intent);
end;

Comments are closed.