打开PDF文件Delphi RIO

问题描述 投票:0回答:1

我想打开在我的应用程序中本地分配的PDF(仅适用于ANDROID,但我完全没有得到。)>

我已经尝试过此链接:Getting exception while opening PDF file for Android 26 using Firemonkey/Delphi,但在Delphi RIO中不起作用。

所以我一直在寻找并获得以下代码:

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;

在此链接上找到哪个:Getting exception while opening PDF file for Android 26 using Firemonkey/Delphi

我做的与写的完全一样,但是返回了以下错误:

java; lang; NullPointerException:尝试调用虚拟方法'android.content.res.XmlResourceParser android.content.pm.PackageItemInfo.loadXmlMetaData(android.content.pm.PackageManager,java.lang; String)'引用空对象

现在正在提供:

java.kabg.illegalArgumentExcpetion:无法找到配置的根包含/data/data/com.embarcadero.ART_Dinamica/files/PRO_Topo.pdf。

PS:我将我的pdf(PRO_Topo.pdf)放入部署中,而远程补丁为“。\ assets \ internal”

我认为我需要放入“ AndroidManifest”,但我已经对其进行了研究,不确定如何设置。 (此错误已使我困扰了一个多月。我跳过了这部分代码来执行其他操作,但是由于这个原因,我再次无法继续执行此操作)

我从文件提供者驱动器获得的GIT链接是这样的:https://github.com/DelphiWorlds/KastriFree/blob/master/API/DW.Androidapi.JNI.FileProvider.pas

如果有人可以帮助我,我将非常感激。

下面我将离开我的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) -->

现在我的AndroidManifest是:

<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) -->

我的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

我想打开一个在我的应用程序中本地分配的PDF(仅适用于ANDROID),但我完全没有。我已经尝试过此链接:打开Android的PDF文件时出现异常...

android delphi firemonkey pascal
1个回答
0
投票

问题归结为由Delphi生成的provider_paths.xml文件中缺少条目。为了使您的方案起作用,该文件应如下所示:

© www.soinside.com 2019 - 2024. All rights reserved.