Vitaliy 1 Posted March 23, 2021 (edited) Hello tell me where I made a mistake? I want to open a PDF file in WebBrowser (which I transfer to my smartphone as part of the apk). I add my pdf file to Deployment (picture 001). I use the following code: unit Unit2; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.StdCtrls, FMX.WebBrowser, IOUtils, System.Permissions, Androidapi.Jni.Os, Androidapi.Helpers, FMX.Memo.Types, FMX.ScrollBox, FMX.Memo; type TForm2 = class(TForm) WebBrowser1: TWebBrowser; Button1: TButton; Label1: TLabel; Button2: TButton; Button3: TButton; Button4: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form2: TForm2; FPermissionWrite: string; FPermissionRead: string; fileName:string; implementation {$R *.fmx} procedure TForm2.Button1Click(Sender: TObject); begin fileName:= (TPath.Combine(TPath.GetSharedDownloadsPath,'001.pdf')); if FileExists(fileName) then WebBrowser1.Navigate('file:/'+fileName) else ShowMessage('11:'); end; procedure TForm2.Button2Click(Sender: TObject); begin Application.Terminate; end; procedure TForm2.Button4Click(Sender: TObject); begin PermissionsService.RequestPermissions([FPermissionWrite], procedure(const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>) begin if (Length(AGrantResults) = 1) and (AGrantResults[0] = TPermissionStatus.Granted) then ShowMessage('Access is available') else ShowMessage('Permission Denied'); end); if PermissionsService.IsPermissionGranted (JStringToString(TJManifest_Permission.JavaClass.WRITE_EXTERNAL_STORAGE)) and PermissionsService.IsPermissionGranted (JStringToString(TJManifest_Permission.JavaClass.READ_EXTERNAL_STORAGE)) then ShowMessage ('access has ALREADY been granted!') else ShowMessage ('001'); end; procedure TForm2.FormCreate(Sender: TObject); begin FPermissionWrite := JStringToString(TJManifest_permission.JavaClass.WRITE_EXTERNAL_STORAGE); FPermissionRead := JStringToString(TJManifest_permission.JavaClass.READ_EXTERNAL_STORAGE); end; end. here WebBrowser1.Navigate ('file:/' +fileName) error occurs: the specified file was not found on a smartphone, the file is created at: /storage/emulated/0/Android/data/com.embarcadero.Project5/files/001.pdf Edited March 23, 2021 by Vitaliy Share this post Link to post
Guest Posted March 23, 2021 (edited) hi @Vitaliy about ask permissions, try my sample... you need as the ALL permitions using same procedure, not 2 as above. for easy use, try define this procedure in another place in your code for many others use: another thing, a procedure can be define and referenced by a "TProc" type, as: var xxx : TProc; ... procedure ZZZZ; ... xxx := ZZZZ you see? Maybe your PDF should be in ".\assets\internal" not in "assets" just. if your PDF dont open, can be that your system do the "download of PDF" not "open PDF" you see? then, in your system you need define that PDF files should be opened, not downloaded. hug Edited March 23, 2021 by Guest Share this post Link to post