Android Question get the file path from contentchooser When the return value of filename is URI

xytz86

New Member
I want to get the file path from contentchooser so that I can read the file content using "file. Openinput()". When the return value of filename is URI.
I use Huawei mobile phone test to return the URI as follows"content://com.android.providers.downloads.documents/document/msf%3A1445720",
and another mobile phone test returns the real path as follows"/storage/emulated/0/Android/data/com.tencent.mobileqq/Tencent/QQfile_recv/*****.TXT"
B4X:
Dim cc As ContentChooser
            cc.Initialize("cc")
            cc.Show("text/*", "Choose text file")
            Wait For cc_Result(Success As Boolean, Dir As String, FileName As String)
            Dim res As LoadResult = CreateLoadResult(FileName)
            Dim tr As TextReader
                tr.Initialize(File.OpenInput(res.FileName,res.Dir))       
                Dim line As String
                Do While line <> Null
                    line = tr.ReadLine
                    If line<> Null Then
                            WriteHrtDB(line) 
                    End If
                
                Loop
            End If

please tell me what to do.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Solution

xytz86

New Member
Don't use TextReader: https://www.b4x.com/android/forum/threads/b4x-features-that-erel-recommends-to-avoid.133280/#content

B4X:
Dim cc As ContentChooser
cc.Initialize("cc")
cc.Show("text/*", "Choose text file")
Wait For cc_Result(Success As Boolean, Dir As String, FileName As String)
If Success Then
 Dim Lines As List = File.ReadList(Dir, FileName)
End If

Forget from accessing the remote uri as if it is a regular file. It isn't.
Thank you for your answer. It solved my problem perfectly.
 
Upvote 0
Top