Hello StackOverflow's team,
With Delphi Rio, I have an Android app whose I want to send an email with attached zip file.
Regarding to the following link, I can do this with Delphi Tokyo (devices 6.0, 8.0 and 8.1) but it doesn't work with Rio: the app closes with 8.0 + 8.1 devices without any message error. It works on my 6.0 device.
How to send email with attachment using default Android email app - Delphi XE7
Zip file has been created before calling CreateEmail procedure.
This link stackoverflow.com/a/53605468/3164070 really helped me but now I have 2 destination adresses:
- _Recipient which is OK
- //com.embarcadero.MyApp.fileprovider/external_files/MyApp/Tmpdir/TmpFile.zip which is wrong...
How can I remove the wrong adress ?
Here is my procedure:
procedure CreateEmailTest(const _Recipient, _Subject, _Content, _Attachment: string);
var LIntent: JIntent;
LAuthority: JString;
LUri: Jnet_Uri;
JRecipient: TJavaObjectArray<JString>;
begin
LAuthority := StringToJString(JStringToString(TAndroidHelper.Context.getApplicationContext.getPackageName) + '.fileprovider');
LUri := TJFileProvider.JavaClass.getUriForFile(TAndroidHelper.Context, LAuthority, TJFile.JavaClass.init(StringToJString(_Attachment)));
LIntent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_SEND);
JRecipient := TJavaObjectArray<JString>.Create(1);
JRecipient.Items[0] := StringToJString(_Recipient);
LIntent.removeExtra(StringToJString(_Attachment));//do not remove wrong email adress
LIntent.removeExtra(TJIntent.JavaClass.EXTRA_EMAIL) ;//do not remove wrong email adress
LIntent.putExtra(TJIntent.JavaClass.EXTRA_EMAIL, JRecipient);
LIntent.putExtra(TJIntent.JavaClass.EXTRA_SUBJECT, StringToJString(_Subject));
LIntent.putExtra(TJIntent.JavaClass.EXTRA_TEXT, StringToJString(_Content));
LIntent.putExtra(TJIntent.JavaClass.EXTRA_STREAM, TJParcelable.Wrap((LUri as ILocalObject).GetObjectID)); // ajout de la pièce jointe
LIntent.setDataAndType(LUri, StringToJString('vnd.android.cursor.dir/email'));
TAndroidHelper.Activity.startActivity(LIntent);
end;
Regards,
Lefjucabro