Android Question ContentChooser for PDF File

scsjc

Well-Known Member
Licensed User
Longtime User
Hi, I'm using the ContentChooser to locate a PDF on the android, and pass it to a copy file.
Apparently it works correctly, I would like to know if it is correct like this, or is there any recommended method?


B4X:
dim cc As ContentChooser
cc.Initialize("cc")
cc.Show("application/pdf", "Choose pdf")

....

Sub cc_Result (Success As Boolean, Dir As String, filename As String)
    If Success=True Then
        If File.Exists(Starter.Provider.SharedFolder,"file.pdf") Then File.Delete (Starter.Provider.SharedFolder,"file.pdf")
        Dim jo As JavaObject
        Dim cd As String = jo.InitializeStatic("anywheresoftware.b4a.objects.streams.File").GetField("ContentDir")
        Dim in As InputStream = File.OpenInput(cd, filename)
        Dim out As OutputStream = File.OpenOutput(Starter.Provider.SharedFolder,"file.pdf", False)
        File.Copy2(in,out)
        out.Close
        If File.Exists(Starter.Provider.SharedFolder,"file.pdf") Then
                 ....
        End If
    End If
end sub
 

scsjc

Well-Known Member
Licensed User
Longtime User
Where does this code come from?

Why not:
B4X:
Sub cc_Result (Success As Boolean, Dir As String, filename As String)
    If Success=True Then
        File.Copy(Dir, FileName, Starter.Provider.SharedFolder,"file.pdf")
    End If
end sub


šŸ˜….... thanks .... too many hours working are to blame for not seeing the obvious
 
Upvote 0
Top