Open PDF file Delphi RIO

  

I would like to open a PDF that is allocated locally in my application (ANDROID only), but I am not getting it at all.

I already tried this link: Getting exception while opening PDF file for Android 26 using Firemonkey/Delphi but not work in Delphi RIO.

So I kept looking and got this code:

procedure TF_NovaART.PRO_MapeaClick(Sender: TObject);
var
fName : String;
LIntent: JIntent;
LAuthority: JString;
LUri: Jnet_Uri;
begin
fName := TPath.GetDocumentsPath + PathDelim + ‘PRO_Topo.pdf’;

{$IFDEF ANDROID}
LAuthority := StringToJString(JStringToString(TAndroidHelper.Context.getApplicationContext.getPackageName) + ‘.fileprovider’);
LUri := TJFileProvider.JavaClass.getUriForFile(TAndroidHelper.Context, LAuthority, TJFile.JavaClass.init(StringToJString(fName)));
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);

{$ENDIF}

end;

Which was found on this link: Getting exception while opening PDF file for Android 26 using Firemonkey/Delphi

I did exactly as it is written, but returns me the following error:

java;lang;NullPointerException: Attempt to invoke virtual method
‘android.content.res.XmlResourceParser android.content.pm.Package
ItemInfo.loadXmlMetaData(android.content.pm.PackageManager,
java.lang;String)’ on a null object reference

now it’s giving :

java.kabg.illegalArgumentExcpetion: Failed to find configurated root
that contains
/data/data/com.embarcadero.ART_Dinamica/files/PRO_Topo.pdf.

PS: I put my pdf (PRO_Topo.pdf) in the deployment and the remote patch is “.\assets\internal”

I think I need to put in the “AndroidManifest”, but I’ve already researched it and I’m not sure how to set it. (This bug has been stalking me for over a month. I skipped this part of the code to do other things, but again I’m unable to continue because of it)

The GIT link I got from the File Provider drive is this: https://github.com/DelphiWorlds/KastriFree/blob/master/API/DW.Androidapi.JNI.FileProvider.pas

If anyone can help me I will be sooo grateful.

Below I will leave my AndroidManifest.template.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<!– BEGIN_INCLUDE(manifest) –>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android”
package=”%package%”
android:versionCode=”%versionCode%”
android:versionName=”%versionName%”
android:installLocation=”%installLocation%”>

<uses-sdk android:minSdkVersion=”%minSdkVersion%”
android:targetSdkVersion=”%targetSdkVersion%” />
<%uses-permission%>
<uses-feature android:glEsVersion=”0x00020000″ android:required=”True”/>
<application android:persistent=”%persistent%”
android:restoreAnyVersion=”%restoreAnyVersion%”
android:label=”%label%”
android:debuggable=”%debuggable%”
android:largeHeap=”%largeHeap%”
android:icon=”%icon%”
android:theme=”%theme%”
android:hardwareAccelerated=”%hardwareAccelerated%”
android:resizeableActivity=”false”>

<%provider%>
<%application-meta-data%>
<%services%>
<!– Our activity is a subclass of the built-in NativeActivity framework class.
This will take care of integrating with our NDK code. –>
<activity android:name=”com.embarcadero.firemonkey.FMXNativeActivity”
android:label=”%activityLabel%”
android:configChanges=”orientation|keyboard|keyboardHidden|screenSize”
android:launchMode=”singleTask”>
<!– Tell NativeActivity the name of our .so –>
<meta-data android:name=”android.app.lib_name”
android:value=”%libNameValue%” />
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
<%activity%>
<%receivers%>
</application>
</manifest>
<!– END_INCLUDE(manifest) –>

Now my AndroidManifest is:

<uses-sdk android:minSdkVersion=”19″ android:targetSdkVersion=”26″ />
<uses-permission android:name=”android.permission.ACCESS_COARSE_LOCATION” />
<uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION” />
<uses-permission android:name=”android.permission.CALL_PHONE” />
<uses-permission android:name=”android.permission.CAMERA” />
<uses-permission android:name=”android.permission.INTERNET” />
<uses-permission android:name=”android.permission.READ_EXTERNAL_STORAGE” />
<uses-permission android:name=”android.permission.READ_PHONE_STATE” />
<uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE” />

<uses-feature android:glEsVersion=”0x00020000″ android:required=”True”/>
<application android:persistent=”False”
android:restoreAnyVersion=”False”
android:label=”ART_Dinamica”
android:debuggable=”True”
android:largeHeap=”False”
android:icon=”@drawable/ic_launcher”
android:theme=”@style/AppTheme”
android:hardwareAccelerated=”true”
android:resizeableActivity=”false”>

<provider
android:name=”android.support.v4.content.FileProvider”
android:authorities=”com.embarcadero.ART_Dinamica.fileprovider”
android:exported=”false”
android:grantUriPermissions=”true”>
<meta-data android:name=”android.support.FILE_PROVIDER_PATHS”

android:resource=”@xml/provider_paths”/>

<!– Our activity is a subclass of the built-in NativeActivity framework class.
This will take care of integrating with our NDK code. –>
<activity android:name=”com.embarcadero.firemonkey.FMXNativeActivity”
android:label=”ART_Dinamica”
android:configChanges=”orientation|keyboard|keyboardHidden|screenSize”
android:launchMode=”singleTask”>
<!– Tell NativeActivity the name of our .so –>
<meta-data android:name=”android.app.lib_name”
android:value=”ART_Dinamica” />
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>

<receiver android:name=”com.embarcadero.rtl.notifications.NotificationAlarm” />

</application> </manifest> <!– END_INCLUDE(manifest) –>

My provider_paths.xml:

<?xml version=”1.0″ encoding=”utf-8″?>
<paths xmlns:android=”http://schemas.android.com/apk/res/android”>
<external-path name=”external_files” path=”.”/>
</paths>

Deployment image

Comments are closed.