Search code examples
androidiosdelphifiremonkey

How to open default file manager


I use Delphi 10.3 for Android and IOS app.

I would like to open the default file manager as it opens for me to click add an attachment, eg in gmail.

To take any image from the device I use the TakePhotoFromLibraryAction action. How to do the same for PDF file ?


Solution

  • If you're using Delphi 10.3.x, this will open a PDF on Android if you have a PDF viewer installed:

    procedure OpenPDF(const AFileName: string);
    var
      LIntent: JIntent;
      LUri: Jnet_Uri;
    begin
      LUri := TAndroidHelper.JFileToJURI(TJFile.JavaClass.init(StringToJString(AFileName)));
      LIntent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_VIEW);
      LIntent.setDataAndType(LUri, StringToJString('application/pdf'));
      LIntent.setFlags(TJIntent.JavaClass.FLAG_GRANT_READ_URI_PERMISSION);
      TAndroidHelper.Activity.startActivity(LIntent);
    end;
    

    For iOS, one way is to use the QuickLook framework, which the DPF project has wrapped:

    https://sourceforge.net/projects/dpfdelphiios/

    They have a PDF Viewer demo that may help