Android Question Open a pdf file

Yayou49

Active Member
Licensed User
Hi,
Using code like this:

Code: Copy
Sub Activity_Create(FirstTime As Boolean)
    File.Copy(File.DirAssets,"2.pdf",Starter.Shared,"2.pdf")    
    Dim intent As Intent
    intent.Initialize(intent.ACTION_VIEW,CreateFileProviderUri(Starter.Shared,"2.pdf"))
    intent.SetType("application/pdf")
    intent.WrapAsIntentChooser("Choose PDF Viewer")
    StartActivity(intent)
End Sub

Sub CreateFileProviderUri (Dir As String, FileName As String) As Object
    Dim FileProvider As JavaObject
    Dim context As JavaObject
    context.InitializeContext
    FileProvider.InitializeStatic("android.support.v4.content.FileProvider")
    Dim f As JavaObject
    f.InitializeNewInstance("java.io.File", Array(Dir, FileName))
    Return FileProvider.RunMethod("getUriForFile", Array(context, Application.PackageName & ".provider", f))   'ERROR HERE
End Sub

My manifest:
AddManifestText(<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
)

AddApplicationText(
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="$PACKAGE$.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
)
CreateResource(xml, provider_paths,
<external-files-path name="name" path="" />
)

I have 2 problems to solve:
1) on my physical device, when launch the apk, after requesting the app to use to open, I can see the Adobe pdf app icone 1 second and nothing more.
My pdf file is well stored and I can open it directly via adobe reader

2) How to get adobe reader on Android emulator for my test in debug mode ?

Thanks in advance for your help
 
Hello Yayou and Erel , i have the same error here :

Code: Copy
 Return FileProvider.RunMethod("getUriForFile", Array(context, Application.PackageName & ".provider", f))   'ERROR HERE

i have android 7 on moto g5

The error :

Code: Copy
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference
 
Upvote 0
@Yayou49 try to install a different PDF app.

Unfortunately, even with 3 differents pdf reader, problem is the same.
One of them send me an error "File loading error" while in the same time, open it manually on my phone with adobe reader,pdf is ok ....
 
Upvote 0
even with a JPG file, it doesn't work....
Please find enclose the zip file with a small project (pdf + JPG).
 

Attachments

Upvote 0
Back
Top