1

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 ?

Olaf
  • 215
  • 2
  • 14

1 Answers1

2

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

Dave Nottage
  • 3,411
  • 1
  • 20
  • 57
  • This is an example that I will surely use for some time. Thank you! But to use the QuickLook I have to select the file first. And mainly it was in my question. How can I display the file manager so that the user can choose any file. The selected file will then be sent to the server. – Olaf Aug 05 '19 at 09:51
  • 1
    In which case, you might like to look at: https://stackoverflow.com/a/49332704/3164070. It's in Java, however it should be relatively easy to convert to Delphi. On iOS, you might be able to use this class: https://developer.apple.com/documentation/uikit/uidocumentpickerviewcontroller?language=objc. A quick search has not turned up any Delphi code using it. – Dave Nottage Aug 05 '19 at 10:23
  • 1
    Bear in mind that with UIDocumentPickerViewController, it will show only files that are shared from apps on the device. If you want to list files contained in your app, you will need to either use the UIFileSharingEnabled flag or write your own code to present the files, such as in a listbox. – Dave Nottage Aug 05 '19 at 11:48