unit ShareFileForm;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, System.Actions,
FMX.ActnList, FMX.Controls.Presentation, FMX.StdCtrls,
FMX.StdActns, ioutils, FMX.MediaLibrary.Actions
{$IFDEF Android}
, Androidapi.JNI.Os
, Androidapi.JNI.GraphicsContentViewText
, Androidapi.JNI.JavaTypes
, Androidapi.Helpers
, Androidapi.JNI.Net
, Androidapi.JNI.Webkit
, DW.Androidapi.JNI.FileProvider
{$ENDIF}
;
type
TForm1 =
class(TForm)
Button2: TButton;
procedure Button2Click(Sender: TObject);
private
{ Private-Deklarationen }
fLogFile:
String;
{$IFDEF Android}
intent: JIntent;
{$ENDIF}
Procedure generateFile;
Procedure ShareFileProvide(file_name:
string);
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
Const Loremipsum = '
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ultricies sem a feugiat vulputate.'+
'
Nam euismod vitae nibh pulvinar ornare. Aliquam in tincidunt eros, eu viverra mi. Proin rutrum '+
'
faucibus turpis vel pulvinar. Maecenas a mauris ac lectus feugiat dictum. Vestibulum mollis purus'+
'
quis massa finibus, non pellentesque lorem porta. Maecenas ullamcorper eleifend justo, et suscipit'+
'
ligula consectetur tincidunt. Fusce ut egestas ligula. In malesuada venenatis dui, et aliquet sem'+
'
hendrerit in. Nulla metus risus, laoreet vel ornare id, condimentum nec mauris. Vestibulum nibh urna,'+
'
pellentesque non semper non, condimentum sed mi. Nunc non justo et ante finibus euismod. Nunc nulla ante,'+
'
hendrerit ut pulvinar scelerisque, sollicitudin at tellus. Integer accumsan eu arcu in luctus.'+
'
In eros leo, convallis non ullamcorper nec, convallis eu augue.';
procedure TForm1.Button2Click(Sender: TObject);
begin
generateFile;
ShareFileProvide(fLogfile);
end;
procedure TForm1.generateFile;
begin
{$IFDEF ANDROID}
fLogFile := TPath.Combine(TPath.GetHomePath, '
Testfile.log' );
{$ENDIF}
{$IFDEF IOS}
fLogFile := TPath.Combine(TPath.GetDocumentsPath, '
Testfile.log' );
{$ENDIF}
{$IFDEF WIN32}
fLogFile := TPath.Combine(TPath.GetDirectoryName(paramstr(0)), TPATH.GetFileNameWithoutExtension(paramstr(0)) +'
.log' );
{$ENDIF}
TFile.WriteAllText( fLogFile, Loremipsum, TEncoding.UTF8);
end;
procedure TForm1.ShareFileProvide(file_name:
string);
{$IFDEF Android}
var
ExtFile,deger,id:
string;
mime: JMimeTypeMap;
ExtToMime: JString;
Intent: JIntent;
javafile:JFile;
{$ENDIF}
begin
{$IFDEF Android}
javafile:=TJFile.JavaClass.init(StringToJString(file_name));
ExtFile := AnsiLowerCase(StringReplace(TPath.GetExtension(file_name), '
.', '
',[]));
mime := TJMimeTypeMap.JavaClass.getSingleton();
ExtToMime := mime.getMimeTypeFromExtension(StringToJString(ExtFile));
Intent := TJIntent.Create;
id := JStringToString( TAndroidHelper.Context.getApplicationContext.getPackageName ) + '
.fileprovider';
deger := JURIToStr( TJFileProvider.JavaClass.getUriForFile( TAndroidHelper.Context,
StringToJString(id),
javafile)
);
Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
//Intent.setAction(TJIntent.JavaClass.ACTION_SEND);
Intent.setFlags(1);
Intent.setDataAndType(StrToJURI(deger), ExtToMime);
SharedActivity.startActivity(Intent);
{$ENDIF}
end;
end.