Jump to content

MichaMD

Members
  • Content Count

    2
  • Joined

  • Last visited

Community Reputation

0 Neutral

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. MichaMD

    Android. FileUriExposedException: file:///

    That was what i meant with "activated "save exchange" ", got lost in translation. Something i only found here.^^ My Code example: unit Main; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, FMX.Controls.Presentation, System.IOUtils, System.Messaging, System.StrUtils, FMX.Edit, FMX.Layouts, Androidapi.JNI.Net, Androidapi.JNI.App, Androidapi.JNI.JavaTypes, Androidapi.JNI.Os, Androidapi.JNI.GraphicsContentViewText, Androidapi.Helpers, Androidapi.JNIBridge, Androidapi.JNI.Media, Androidapi.JNI.Support; type TForm1 = class(TForm) GridPanelLayout1: TGridPanelLayout; Button1: TButton; EmailAddy: TEdit; Betreff: TEdit; Text: TEdit; procedure Button1Click(Sender: TObject); private { Private-Deklarationen } procedure CreateCSVForAttachment(Path:string); Procedure SendMail(const Recipient, Subject, MailBody, Attachment: string); public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.fmx} procedure TForm1.Button1Click(Sender: TObject); var FileToWrite: string; TestRecipient: string; TestSubject: string; TestMailBody: string; begin FileToWrite:='Example.csv'; TestRecipient:='Dummy.Dummy@Dummy.de'; TestSubject:='Emailtest'; TestMailBody:='blabla'; CreateCSVForAttachment(System.IOUtils.TPath.GetDocumentsPath + System.SysUtils.PathDelim + FileToWrite); //crate file to try sending SendMail(TestRecipient,TestSubject,TestMailBody,System.IOUtils.TPath.GetDocumentsPath + System.SysUtils.PathDelim + FileToWrite); end; Procedure TForm1.CreateCSVForAttachment(Path:string); var strList: TStringList; a:string; begin StrList := TStringList.Create; a:='Lorem ipsum dolor sit amet, consetetur sadipscing elitr,'; StrList.Add(a); a:='Lorem ipsum dolor sit amet: consetetur sadipscing elitr:'; StrList.Add(a); a:='Lorem ipsum dolor sit amet; consetetur sadipscing elitr;'; StrList.Add(a); try begin StrList.SaveToFile(Path); showmessage(Path); end; finally StrList.Free; end; end; Procedure TForm1.SendMail(const Recipient, Subject, MailBody, Attachment: string); var Intent: JIntent; listRecipients: TJavaObjectArray<JString>; Data:Jnet_Uri; AttachmentFile: JFile; begin listRecipients:=TJavaObjectArray<JString>.Create(1); listRecipients.Items[0]:= StringToJString(Recipient); Intent:= TJIntent.create; Intent.setAction(TJIntent.javaClass.ACTION_SEND); Intent.setFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK); //Found many Codeexamples without this part, necessary? Intent.putExtra(TJIntent.javaClass.EXTRA_EMAIL,listRecipients); //Intent.putExtra(TJIntent.javaClass.EXTRA_CC,listRecipients); //Intent.putExtra(TJIntent.javaClass.EXTRA_Bcc,listRecipients); Intent.putExtra(TJIntent.javaClass.EXTRA_SUBJECT,StringToJString(Subject)); Intent.putExtra(TJIntent.javaClass.EXTRA_TEXT,STringToJString(MailBody)); if Attachment<>'' then begin if TJBuild_Version.JavaClass.SDK_INT>=TJBuild_VERSION_CODES.JavaClass.N then begin AttachmentFile := TJFile.JavaClass.init(StringToJString(Attachment)); //add 'internal_files/'+ ? Intent.addFlags(TJIntent.JavaClass.FLAG_GRANT_READ_URI_PERMISSION); Data:=TJFileProvider.JavaClass.getUriForFile(TAndroidHelper.Context, StringToJString('com.embarcadero.EMail.fileprovider'),AttachmentFile);// Found many Codeexamples with .provider in contrast . fileprovider, //com.embarcadero.projectname.fileprovider ? end else begin Data:=TJnet_Uri.JavaClass.parse(STringToJString('file://'+Attachment)); end; Intent.putExtra(TJIntent.JavaClass.EXTRA_STREAM, TJParcelable.Wrap((Data as ILocalObject).GetObjectID)); //found often TJnet_Uri.JavaClass.fromFile(AttachmentFile); ? end; Intent.setType(StringToJString('vnd.android.cursor.dir/mail')); {tryed "text/plain" or "*/*" or message/rfc822 or vnd.android.cursor.dir/mail or vnd.android.cursor.dir/*} TAndroidHelper.Activity.startActivity(Intent); end; end. Changed AndroidManifest.template.xml: from: <application android:persistent="%persistent%" android:restoreAnyVersion="%restoreAnyVersion%" android:label="%label%" android:debuggable="%debuggable%" android:largeHeap="%largeHeap%" android:icon="%icon%" android:theme="%theme%" android:hardwareAccelerated="%hardwareAccelerated%" android:resizeableActivity="false"> <%provider%> <%application-meta-data%> <%uses-libraries%> to: <application android:persistent="%persistent%" android:restoreAnyVersion="%restoreAnyVersion%" android:label="%label%" android:debuggable="%debuggable%" android:largeHeap="%largeHeap%" android:icon="%icon%" android:theme="%theme%" android:hardwareAccelerated="%hardwareAccelerated%" android:resizeableActivity="false"> <provider android:name="android.support.v4.content.FileProvider" android:authorities="com.embarcadero.Email.fileprovider" android:grantUriPermissions="true" android:exported="false"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/filepaths" /> </provider> <%application-meta-data%> <%uses-libraries%> <%services%> And added Android/Debug/Email/res +xml/filepaths.xml with: <?xml version="1.0" encoding="utf-8"?> <paths> <external-path name="external_files" path="." /> </paths>
  2. MichaMD

    Android. FileUriExposedException: file:///

    Hey, i'm trying to follow your example.=) But i get a problem. It does not work.... XD i get a popup: java.lang.nullpointerException:attempt to invoke virtual method 'android.content.res.xmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager,Java.lang.String)' on a null object reference. Do you have any idea, what the problem could be? I already tried it with files-path vs. external-path in the xml, with or without <paths xmlns:android="http://schemas.android.com/apk/res/android">, activated "save exchange" and wrote and deleted the provider in different parts of the manifest.=/
×