I\'m using Delphi 10.1 Berlin for developing Android mobile application and I need to open the PDF file from the application but I\'m getting the error - android.os.File
You'll need this unit:
https://github.com/DelphiWorlds/KastriFree/blob/master/API/DW.Androidapi.JNI.FileProvider.pas
for this code:
uses
Androidapi.JNI.JavaTypes, Androidapi.JNI.Net, Androidapi.JNI.GraphicsContentViewText, Androidapi.Helpers;
procedure OpenPDF(const AFileName: string);
var
LIntent: JIntent;
LAuthority: JString;
LUri: Jnet_Uri;
begin
LAuthority := StringToJString(JStringToString(TAndroidHelper.Context.getApplicationContext.getPackageName) + '.fileprovider');
LUri := TJFileProvider.JavaClass.getUriForFile(TAndroidHelper.Context, LAuthority, 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;