**EDIT** Sorted
In case it helps others
Selecting and viewing an external PDF file (whereby the external viewer is offered to the user)
Copying the external file to Dir.Internal
I have tried many many examples from the forums here but just can't figure out how to obtain external files using ContentChooser and the FileProvider method.
I want to both view a file (n this case a PDF) from downloads folder (for example) by letting the OS choose the external viewer, then at a later point send this file as an email attachment.
The key problem is that content chooser returns a uri and I don't know how to then use this in conjunction with the FileProvider.
How would I pass this to the Provider? I think I need to copy the file to Dir.Internal then open it that way right?
In case it helps others
Selecting and viewing an external PDF file (whereby the external viewer is offered to the user)
B4X:
' NOTE: Define cc as ContentChooser in Process_Globals
' file selector for pdf
cc.Initialize("PDFChooser")
cc.Show("application/pdf","Choose *.pdf file")
Wait for PDFChooser_Result (Success As Boolean, Dir As String, fileURI As String)
If Success = True Then
Dim in As Intent
in.Initialize(in.ACTION_VIEW, fileURI)
in.Flags=1 ' READ PERMISSION
in.SetComponent("android/com.android.internal.app.ResolverActivity")
in.SetType("application/pdf")
StartActivity(in)
End If
Copying the external file to Dir.Internal
B4X:
Try
Dim OutStr As OutputStream = File.OpenOutput(File.DirInternal,"PDFNameHere.pdf",False)
Dim InStr As InputStream = File.OpenInput("ContentDir",fileURI)
File.Copy2(InStr,OutStr)
OutStr.Close
Catch
Log(LastException)
End Try
Last edited: