R RJB Active Member Licensed User Longtime User Feb 7, 2018 #1 Continuation of 'Wrong File/ Contents' thread as requested. I'm trying to set/ reset the background image of a webview by loading this HTML: Code: Copy File.WriteString(rpDIRoot, "index.html", _ "<html>" & CRLF & _ "<style type=""text/css"">" & CRLF & _ "<!--" & CRLF & _ "body {" & CRLF & _ "background-image: url(" & DIImagePath & ");" & CRLF & _ "background-repeat: no-repeat;" & CRLF & _ "background-size: 100% 100%;" & CRLF & _ "}" & CRLF & _ "-->" & CRLF & _ "</style>" & CRLF & _ "</body>" & CRLF & _ "</html>") DIImagePath is the path/ filename to the image file. I've tried both 'loadurl' and 'loadhtml' but on re-loading (i.e. loading the html the second or third time with different imagepaths) the image isn't correct. It reverts to previous images. To prove the imagepath is correct I have tried loading it to an imageview just before the loadurl/ loadhtml. The image in the imageview is always correct. Code: Copy If Not(testpicbox.IsInitialized) Then testpicbox.Initialize("") testpicbox.RemoveView Activity.AddView(testpicbox, 0, 0, 400, 300) testpicbox.Bitmap = LoadBitmapSample("", DIImagePath, 400, 300) testpicbox.BringToFront I've tried initializing the wv just before loading the html but this just leaves a blank screen, no image. I've tried clearing the background first with: Code: Copy "<html>" & CRLF & _ "<body>" & CRLF & _ "</body>" & CRLF & _ "</html>" but the wrong image is still displayed.
Continuation of 'Wrong File/ Contents' thread as requested. I'm trying to set/ reset the background image of a webview by loading this HTML: Code: Copy File.WriteString(rpDIRoot, "index.html", _ "<html>" & CRLF & _ "<style type=""text/css"">" & CRLF & _ "<!--" & CRLF & _ "body {" & CRLF & _ "background-image: url(" & DIImagePath & ");" & CRLF & _ "background-repeat: no-repeat;" & CRLF & _ "background-size: 100% 100%;" & CRLF & _ "}" & CRLF & _ "-->" & CRLF & _ "</style>" & CRLF & _ "</body>" & CRLF & _ "</html>") DIImagePath is the path/ filename to the image file. I've tried both 'loadurl' and 'loadhtml' but on re-loading (i.e. loading the html the second or third time with different imagepaths) the image isn't correct. It reverts to previous images. To prove the imagepath is correct I have tried loading it to an imageview just before the loadurl/ loadhtml. The image in the imageview is always correct. Code: Copy If Not(testpicbox.IsInitialized) Then testpicbox.Initialize("") testpicbox.RemoveView Activity.AddView(testpicbox, 0, 0, 400, 300) testpicbox.Bitmap = LoadBitmapSample("", DIImagePath, 400, 300) testpicbox.BringToFront I've tried initializing the wv just before loading the html but this just leaves a blank screen, no image. I've tried clearing the background first with: Code: Copy "<html>" & CRLF & _ "<body>" & CRLF & _ "</body>" & CRLF & _ "</html>" but the wrong image is still displayed.
eps Expert Licensed User Longtime User Feb 7, 2018 #2 Which 'file' are you reloading when you reload? The initial version or a saved version? Where are you looking for the file? The /resources subdirectory is read only iirc. So you may well need to copy the files to a read/write area load this and then update it there and reference from there. Hopefully this makes sense! Upvote 0
Which 'file' are you reloading when you reload? The initial version or a saved version? Where are you looking for the file? The /resources subdirectory is read only iirc. So you may well need to copy the files to a read/write area load this and then update it there and reference from there. Hopefully this makes sense!
R RJB Active Member Licensed User Longtime User Feb 7, 2018 #3 eps said: Which 'file' are you reloading when you reload? The initial version or a saved version? Where are you looking for the file? The /resources subdirectory is read only iirc. So you may well need to copy the files to a read/write area load this and then update it there and reference from there. Hopefully this makes sense! Click to expand... Thanks for the suggestion, eps. I've done some more investigating and found that the problem is caused by re-using the same file name. If the name is the same then the Webview must assume that there is no change, even though the file contents have changed. The attached code shows the problem. Attachments Webview Problem.zip Webview Problem.zip 35 KB · Views: 495 Upvote 0
eps said: Which 'file' are you reloading when you reload? The initial version or a saved version? Where are you looking for the file? The /resources subdirectory is read only iirc. So you may well need to copy the files to a read/write area load this and then update it there and reference from there. Hopefully this makes sense! Click to expand... Thanks for the suggestion, eps. I've done some more investigating and found that the problem is caused by re-using the same file name. If the name is the same then the Webview must assume that there is no change, even though the file contents have changed. The attached code shows the problem.
eurojam Well-Known Member Licensed User Longtime User Feb 7, 2018 #4 May be it is a cache problem, did you try to use WebViewExtras and then clearCache Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Feb 7, 2018 #5 RJB said: File.WriteString(rpDIRoot, "index.html", _ "<html>" & CRLF & _ "<style type=""text/css"">" & CRLF & _ "<!--" & CRLF & _ "body {" & CRLF & _ "background-image: url(" & DIImagePath & ");" & CRLF & _ "background-repeat: no-repeat;" & CRLF & _ "background-size: 100% 100%;" & CRLF & _ "}" & CRLF & _ "-->" & CRLF & _ "</style>" & CRLF & _ "</body>" & CRLF & _ "</html>") Click to expand... Use smart strings: http://etp.b4x.com/video/252694269 You can add a stub parameter to the files. I'm not sure whether the problem is with index.html or the image name. Add ?stub=${DateTime.Now} to both of them. Upvote 0
RJB said: File.WriteString(rpDIRoot, "index.html", _ "<html>" & CRLF & _ "<style type=""text/css"">" & CRLF & _ "<!--" & CRLF & _ "body {" & CRLF & _ "background-image: url(" & DIImagePath & ");" & CRLF & _ "background-repeat: no-repeat;" & CRLF & _ "background-size: 100% 100%;" & CRLF & _ "}" & CRLF & _ "-->" & CRLF & _ "</style>" & CRLF & _ "</body>" & CRLF & _ "</html>") Click to expand... Use smart strings: http://etp.b4x.com/video/252694269 You can add a stub parameter to the files. I'm not sure whether the problem is with index.html or the image name. Add ?stub=${DateTime.Now} to both of them.
R RJB Active Member Licensed User Longtime User Feb 7, 2018 #6 Thanks eurojam. It's obvious now you've pointed it out! This code: Code: Copy Dim r As Reflector r.target = WebView1 r.runmethod2("clearCache","True", "java.lang.boolean") from: https://www.b4x.com/android/forum/threads/clear-webview-cache.10382/#post-65532 did the trick. Thanks also Erel for your patience in this and the original thread. Upvote 0
Thanks eurojam. It's obvious now you've pointed it out! This code: Code: Copy Dim r As Reflector r.target = WebView1 r.runmethod2("clearCache","True", "java.lang.boolean") from: https://www.b4x.com/android/forum/threads/clear-webview-cache.10382/#post-65532 did the trick. Thanks also Erel for your patience in this and the original thread.