Android Question How do I get an image in DirAssets to display in a WebView?

Similar threads

B4A Code Snippet [B4X] GUID
B4A Class EscapeXml - Code snippet
B4A Code Snippet [B4X] SQLite case insensitive searches with non-ASCII text
B4A Tutorial TabHost tutorial
B4A Tutorial Text files
B4A Code Snippet [B4X] UrlEncodeMap

davepamn

Active Member
Licensed User
B4X:
    Dim cur As Cursor
    Dim bChkSampleTaken As Boolean=False
    cur = SQLLite.SQL.ExecQuery2(SQLTransactions, Array As String(Dt))
    For row = 0 To cur.RowCount - 1
        cur.Position = row
        sB.Append("<tr>")
        'Set all the columns as clickable.  Map clickable columns in WebView1_OverrideUrl
        For i = 0 To cur.ColumnCount - 1
            bChkSampleTaken=False
            sB.Append("<td>")

            If i=5 Then
                If cur.GetString2(i)="X" Then
                    bChkSampleTaken=True
                End If
            End If

            If bChkSampleTaken=True Then
                sB.Append("<a href='http://").Append(i).Append(".")
                sB.Append(row)
                sB.Append(".com'>").Append("<img src='" & File.DirAssets &"/chksampletaken.jpg" & "' border=0></a>")
            Else
                sB.Append("<a href='http://").Append(i).Append(".")
                sB.Append(row)
                sB.Append(".com'>").Append(cur.GetString2(i)).Append("</a>")
            End If
            sB.Append("</td>")
        Next
        sB.Append("</tr>")
    Next
    sB.Append("</table>")
    WebView1.LoadHtml(sB.ToString)
I added chksampletaken.jpg to the files tab. The image is not showing in release or debug mode.
 

davepamn

Active Member
Licensed User
I don't see an images directory. Do I need to create it?

myapp folders:
1. Files
2. Junk
3. Objects
 

davepamn

Active Member
Licensed User
I created an folder under myApp called images
B4X:
                sB.Append("<a href='http://").Append(i).Append(".")
                sB.Append(row)
                sB.Append(".com'>").Append("<img src='" & File.Dirinternal &"/images/chksampletaken.jpg" & "' border=0/></a>")
The image still does not display
 

davepamn

Active Member
Licensed User
B4X:
           ..
       sB.Append(".com'>").Append("<img src='File:///android_asset/images/chksampletaken.jpg" & "' border=0/></a>")
and
..
               sB.Append(".com'>").Append("<img src='File:///android_asset/chksampletaken.jpg" & "' border=0/></a>")
Both failed
 

NJDude

Expert
Licensed User
You are NOT using lowercase
B4X:
Append("<img src='File:///android_asset/chksampletaken.jpg" & "' border=0/></a>")
The word FILE, has to be all lower case, this works:
B4X:
"<img src='file:///android_asset/chksampletaken.jpg' border=0/></a>"
 
Top