German PDF anzeigen

peternmb

Well-Known Member
Licensed User
Longtime User
Hallo,
ich lasse mit diesem Code in meiner App ein erstelltes PDF anzeigen.
Auf dem Tablet mit Android-12 klappt das problemlos,
auf dem Smartphone mit Android-13 stürzt meine App ab.
Code:
B4X:
            Dim FileName As String = xListFile & ".PDF"
            File.Copy(oListDir, FileName, Starter.Provider.SharedFolder, FileName)
            Dim in As Intent
                '
            in.Initialize(in.ACTION_VIEW, "")
            Starter.Provider.SetFileUriAsIntentData(in, FileName)
            '
            'Type must be set after calling SetFileUriAsIntentData
            in.SetComponent("android/com.android.internal.app.ResolverActivity")
            in.SetType("application/pdf")
            '
            StartActivity(in)

Fehlermeldung:
java.lang.NullPointerException: Attempt to invoke interface method 'java.util.List com.android.server.pm.pkg.component.ParsedMainComponent.getIntents()' on a null object reference
 

peternmb

Well-Known Member
Licensed User
Longtime User
Ich habe im Forum einen Codeschnipsel gefunden, mit dem funktioniert es:
B4X:
        '
        Dim FileName As String = xListFile & ".PDF"
        Dim provider As FileProvider
        provider.Initialize
        ' Copy the file to the shared directory
        Wait For (File.CopyAsync(oListDir, FileName, Starter.Provider.SharedFolder, FileName)) Complete (Success As Boolean)
        '     
        If Success = False Then
            Log("Android - Error: Failed to copy the file to the shared directory.")
            Return
        Else
            Log("Android - File copy successful: " & Success)
        End If
        '
        ' Configure the Intent to open the PDF
        Dim docIntent As Intent
        docIntent.Initialize(docIntent.ACTION_VIEW, "")
        provider.SetFileUriAsIntentData(docIntent, FileName)
        docIntent.SetType("application/pdf")
        docIntent.Flags = Bit.Or(1, 2) ' FLAG_GRANT_READ_URI_PERMISSION
        '
        StartActivity(docIntent)
        '
 
Top