Einzelnen Beitrag anzeigen

QuickAndDirty

Registriert seit: 13. Jan 2004
Ort: Hamm(Westf)
1.944 Beiträge
 
Delphi 12 Athens
 
#4

AW: Share file via Provider

  Alt 26. Mär 2019, 16:21
Also gut.
Habe die FileProvider Unit von Kastrifree in das projekt genommen....
alles andere rausgeschmissen
Delphi-Quellcode:
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.
Leider funktioniert es trotzdem nicht.
Andreas
Monads? Wtf are Monads?
  Mit Zitat antworten Zitat