Android Question Having trouble displaying local images in a webview

doncx

Active Member
Licensed User
Longtime User
I am trying to display local images in a webview using the code below. The full webview also includes other HTML, to which this is appended. <html><body> and </html></body> tags are wrapped around it all. The webview displays everything but the images.

B4X:
    Dim Buffer() As Byte 'declare an empty byte array
    Dim PhotoType As String
    Dim PhotoFilename As String
    Photos = ""
    Dim rs As ResultSet = B4XPages.MainPage.SQL.ExecQuery("SELECT * FROM session_photo where session_id = '" & B4XPages.MainPage.Session.ID & "'")
    Do While rs.NextRow
        Buffer = rs.GetBlob("photo")
        PhotoType = rs.GetString("photo_type")
        PhotoFilename = CodeModule.CreatePhotoFilenameFromData( B4XPages.MainPage.Session.ID, PhotoType )
        File.WriteBytes( B4XPages.MainPage.FilesDir, PhotoFilename, Buffer )
        Photos = Photos & "<p>" & PhotoType & "<br>"
        Photos = Photos & "<img src=""file://" & File.Combine(B4XPages.MainPage.FilesDir, PhotoFilename) & """ style=""width: 90%;""></p>"
    Loop
    Log(Photos)

The Log output shows this HTML:

B4X:
<p>Developing<br><img src="file:///storage/emulated/0/Android/data/b4a.scallops.ondeck/files/photo_49-1680706554760_Developing.jpg" style="width: 90%;"></p><p>Nematodes<br><img src="file:///storage/emulated/0/Android/data/b4a.scallops.ondeck/files/photo_49-1680706554760_Nematodes.jpg" style="width: 90%;"></p>

As you can see from the screenshots I've attached, the photos are indeed there and they are legitimate jpegs, but they don't display in the webview.

The "FilesDir" referenced equates to rp.GetSafeDirDefaultExternal("").

What am I doing wrong?

As always, thanks for any assistance.
 

Attachments

  • scallop-app-filesdir.jpg
    scallop-app-filesdir.jpg
    32.2 KB · Views: 51
  • view-data-no-photos.jpg
    view-data-no-photos.jpg
    17.5 KB · Views: 57

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

doncx

Active Member
Licensed User
Longtime User
Thanks for your reply, but your link refers specifically to rapid debug mode.

I've been working in release mode. I've tried the #DebuggerForceStandardAssets: true declaration and it hasn't made a difference.

Any other ideas?
 
Upvote 0

doncx

Active Member
Licensed User
Longtime User
I have now also tried the "Sub WebViewAssetFile" method also. Still no joy.

What else could it be?
 
Upvote 0

doncx

Active Member
Licensed User
Longtime User
Yup, that's it! I set targetSdkVersion="28" and it works just fine.

Frustrating, how things get deprecated so quickly in Android.

Thank you. I'll look into webviewassetloader.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Very bad: B4XPages.MainPage.SQL.ExecQuery("SELECT * FROM session_photo where session_id = '" & B4XPages.MainPage.Session.ID & "'")

2. Check this: [B4X] Use WebView to show large images
 
Upvote 0

doncx

Active Member
Licensed User
Longtime User
Upvote 0
Top