Sub OpenPDF(dirFile As String, nameFile As String)
Try
#If B4A
' Piattaforma: Android
Dim provider As FileProvider
provider.Initialize
' Copia il file nella directory condivisa
Wait For (File.CopyAsync(dirFile, nameFile, provider.SharedFolder, nameFile)) Complete (Success As Boolean)
Log("Android - Copia del file riuscita: " & Success)
If Success = False Then
Log("Android - Errore: impossibile copiare il file nella directory condivisa.")
Return
End If
' Configura l'Intent per aprire il PDF
Dim docIntent As Intent
docIntent.Initialize(docIntent.ACTION_VIEW, "")
provider.SetFileUriAsIntentData(docIntent, nameFile)
docIntent.SetType("application/pdf")
docIntent.Flags = Bit.Or(1, 2) ' FLAG_GRANT_READ_URI_PERMISSION
StartActivity(docIntent)
#Else If B4I
' Piattaforma: iOS
' Controlla se il file esiste
If File.Exists(dirFile, nameFile) = False Then
Log("iOS - Errore: file PDF non trovato in " & dirFile & "/" & nameFile)
Return
End If
' Inizializza DocumentInteraction per aprire il PDF
Dim docInteraction As DocumentInteraction
docInteraction.Initialize("docInteraction", dirFile, nameFile)
docInteraction.OpenFile(B4XPages.GetNativeParent(Me).RootPanel)
Log("iOS - PDF aperto con successo.")
#Else If B4J
' Piattaforma: Desktop
' Controlla se il file esiste
If File.Exists(dirFile, nameFile) = False Then
Log("B4J - Errore: file PDF non trovato in " & dirFile & "/" & nameFile)
Return
End If
' Apri il PDF utilizzando JFX
Private fx As JFX
fx.ShowExternalDocument(File.GetUri(dirFile, nameFile))
Log("B4J - PDF aperto con successo.")
#End If
Catch
Log("Errore durante l'apertura del PDF: " & LastException)
End Try
End Sub