Hello , i try to open a PDF file from my app on an android 7 with the new permissions functions but when i try to do it, i get this error and a blank screen for a while and nothing more :
i am using b4a 8.50
My code :
i have android 7 on moto g5
The error :
My manifest
Thanks a lot for all your help.
(@Erel new threat created, thanks for any help)
i am using b4a 8.50
My code :
B4X:
Sub Doit()
Dim Mostrador_de_PDF As Intent
Dim uri As Object
Dim p As Phone
Dim Shared As String
Shared = rp.GetSafeDirDefaultExternal("shared")
If p.SdkVersion >= 24 Then
'uri = rp.GetSafeDirDefaultExternal("shared"), "VM_" & Vars.Datos_Recibo.Remision & ".pdf"
uri = CreateFileProviderUri(Shared, "VM_" & Vars.Datos_Recibo.Remision & ".pdf")
Else
uri = "file://" & File.Combine(Shared, "VM_" & Vars.Datos_Recibo.Remision & ".pdf")
End If
BITA("Va a mostrar PDF :" & Vars.Datos_Recibo.Remision)
Mostrador_de_PDF.Initialize(Mostrador_de_PDF.ACTION_VIEW, uri)
Mostrador_de_PDF.PutExtra("android.intent.extra.STREAM", uri)
Mostrador_de_PDF.SetType("application/pdf")
Mostrador_de_PDF.Flags = 1
StartActivity(Mostrador_de_PDF)
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)) < --- HERE THERE ERROR and dont know why ...
End Sub
B4X:
Return FileProvider.RunMethod("getUriForFile", Array(context, Application.PackageName & ".provider", f)) 'ERROR HERE
The error :
B4X:
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
My manifest
B4X:
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
AddManifestText(
<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="26"/>
<uses-feature android:name="android.hardware.location.gps"/>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="$PACKAGE$.provider"
android:exported="false"
android:grantUriPermissions="true">
</provider>
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
CreateResource(xml, provider_paths,
<external-files-path name="name" path="shared" />
)
'End of default text.
Thanks a lot for all your help.
(@Erel new threat created, thanks for any help)