Android Question Opening/Viewing/copying files from downloads folder with ContentChooser

Jim Brown

Active Member
Licensed User
Longtime User
**EDIT** Sorted


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:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…