When targeting newer Android SDK for uploading an app to Google's store I obtain an error when sending a file as an attachment:
android.os.FileUriExposedException: file:///storage/emulated/0/Documents/filename.jpg exposed beyond app through ClipData.Item.getUri()
The code was working fine in Tokyo.
procedure CreateEmail(const Recipient, Subject, Content, Attachment: string);
var
JRecipient: TJavaObjectArray<JString>;
Intent: JIntent;
Uri: Jnet_Uri;
AttachmentFile: JFile;
begin
JRecipient := TJavaObjectArray<JString>.Create(1);
JRecipient.Items[0] := StringToJString(Recipient);
Intent := TJIntent.Create;
Intent.setAction(TJIntent.JavaClass.ACTION_SEND);
Intent.setFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK);
Intent.putExtra(TJIntent.JavaClass.EXTRA_EMAIL, JRecipient);
Intent.putExtra(TJIntent.JavaClass.EXTRA_SUBJECT, StringToJString(Subject));
Intent.putExtra(TJIntent.JavaClass.EXTRA_TEXT, StringToJString(Content));
if Attachment <> '' then
begin
AttachmentFile := TJFile.JavaClass.init(StringToJString(Attachment));
Uri := TJnet_Uri.JavaClass.fromFile(AttachmentFile);
Intent.putExtra(TJIntent.JavaClass.EXTRA_STREAM, TJParcelable.Wrap((Uri as ILocalObject).GetObjectID));
end;
Intent.setType(StringToJString('vnd.android.cursor.dir/email'));
TandroidHelper.Activity.startActivity(Intent);
end;
I have tried different codes I found over there. No one works.
I have activated "Secure File Sharing" in Project Options.
I have tried a code using DW.Androidapi.JNI.FileProvider.pas
But I cannot get one working.
Thanks in advance.