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

Discussion in 'Android Questions' started by davepamn, Jun 4, 2015.

Similar threads

B4A Class EscapeXml - Code snippet
B4A Tutorial TabHost tutorial
B4A Tutorial Text files
B4A Code Snippet Get the APK signature at runtime
B4A Code Snippet MSMySQL_DeleteHelper
B4A Code Snippet Remove accents from string
  1. davepamn

    davepamn Active Member Licensed User

    Code:
    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.
     
  2. thedesolatesoul

    thedesolatesoul Expert Licensed User

    What if you copy the file to dirinternal?
     
  3. davepamn

    davepamn Active Member Licensed User

    what folder under my application is dir.internal
     
    Last edited: Jun 4, 2015
  4. thedesolatesoul

    thedesolatesoul Expert Licensed User

    File.DirInternal
     
  5. davepamn

    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
     
  6. NJDude

    NJDude Expert Licensed User

    To do that you need to do it like this:
    Code:
    "<img src='" & "file:///android_asset/chksampletaken.jpg" & "'"
     
    thedesolatesoul likes this.
  7. davepamn

    davepamn Active Member Licensed User

    I created an folder under myApp called images
    Code:
    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
     
  8. davepamn

    davepamn Active Member Licensed User

    Code:
    ..
           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
     
  9. NJDude

    NJDude Expert Licensed User

    Make sure it's all lower case.
     
  10. davepamn

    davepamn Active Member Licensed User

    all lower case
     
  11. davepamn

    davepamn Active Member Licensed User

    where are you storing your image? Can you give me your image path
     
  12. NJDude

    NJDude Expert Licensed User

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

    Erel Administrator Staff Member Licensed User

Loading...