Android Question ContentChooser - get RealPath from Image

Alexander Stolte

Expert
Licensed User
Longtime User
Hey,

with this code, i get the filename:
B4X:
cc.Show("image/*", "Choose image")
    Wait For cc_Result (Success As Boolean, Dir As String, FileName As String)
    If Success = True Then   
        Log(GetFileInfoByIndex("_display_name", FileName))
    End If
    
    Sub GetFileInfoByIndex(column As String, uri As String) As String
    
    Dim results As String
    Dim Cur As Cursor
    Dim Uri1 As Uri
    Dim cr As ContentResolver
    cr.Initialize("")

    'if viewing by gallery
    If uri.StartsWith("content://media/") Then
        Dim i As Int = uri.LastIndexOf("/")
        Dim id As String = uri.SubString(i + 1)
        Uri1.Parse(uri)
        Cur = cr.Query(Uri1, Null, "_id = ?", Array As String(id), Null)
        Cur.Position = 0
        If Cur.RowCount <> 0 Then
            For i = 0 To Cur.ColumnCount - 1
                If Cur.GetColumnName(i) <> Null Then
                    If Cur.GetColumnName(i) = column Then
                        results = Cur.GetString2(i)
                        Exit
                    End If
                End If
            Next
        End If
    Else
        Uri1.Parse(uri)
        Cur = cr.Query(Uri1, Null, Null, Null, Null)
        Cur.Position = 0
        If Cur.RowCount <> 0 Then
            For i = 0 To Cur.ColumnCount - 1
                If Cur.GetColumnName(i) <> Null Then
                    If Cur.GetColumnName(i) = column Then
                        results = Cur.GetString2(i)
                        Exit
                    End If
                End If
            Next
        End If
    End If
    
    Cur.Close
    
    Return results
    
End Sub
But how to get the path from the content chooser?
What is the sense behind such a dialogue, if you get an uri without the right path.
 

DonManfred

Expert
Licensed User
Longtime User
The Forumsearch is working. You´ll find multiple post asking this. And also you´ll found out that the path is not relevant and there are cases where there is no path at all.

You can easily access the file with the values you get from contentChooser. Access it and copy it to anywhere else you know the path from if you want to.
 
Upvote 0
Top