Android Question What is the idea of browsing the online application offline

alfaiz678

Active Member
Licensed User
What is the idea of browsing the online application offline I have a question about the idea of applying a site that works online, I want if the user browses a section in the application online and then closes the Internet and returns to the application again, he can browse the same section offline
 
Solution
technically, when you browse online, the text, the images and the css styling are
all downloaded to memory. if you turn off the internet, the page is still in memory.
it is possible to find it and browse it from memory (the cache) with a webview, but
it is not easy to find. it has been mentioned here in the forum some time ago.
locating the cache and knowing how to use it will require some research (actually,
a lot of work, i think.)

if the page is mostly text (like a page from a book), an easier solution might be
to download the page with okhttputils2 and save it. you can then load it into a
webview. although this is easier, the problem is that webpages are not usually kept
entirely in 1 file. there are css files, javascript...

drgottjr

Expert
Licensed User
Longtime User
technically, when you browse online, the text, the images and the css styling are
all downloaded to memory. if you turn off the internet, the page is still in memory.
it is possible to find it and browse it from memory (the cache) with a webview, but
it is not easy to find. it has been mentioned here in the forum some time ago.
locating the cache and knowing how to use it will require some research (actually,
a lot of work, i think.)

if the page is mostly text (like a page from a book), an easier solution might be
to download the page with okhttputils2 and save it. you can then load it into a
webview. although this is easier, the problem is that webpages are not usually kept
entirely in 1 file. there are css files, javascript files and actions which require
downloading data (eg, clicking on links). since you will be offline, none of that
will be possible. the most you will get is 1 html file. what is in that file is
difficult to say; you will not know until you try. here's an example:

i assume you are familiar with okhttputils for downloading from the internet.
download the page you want to browse.

ONLINE
B4X:
    j.download("https://www.b4x.com")
    Wait For (j) JobDone(j As HttpJob)

    If j.Success Then
        File.WriteString(File.DirInternal,"b4x.html", j.GetString)
        j.Release
     else
            ....
     end if

NOW OFFLINE
B4X:
        Dim webview1 As WebView
        webview1.Initialize("wv")
        Activity.AddView(webview1,0%x,0%y,100%x,100%y)
        webview1.LoadHtml(File.ReadString(File.DirInternal,"b4x.html"))


i downloaded the b4x homepage and saved it in dir.internal. now i open a webview
and load the file offline. see 2 screen captures below. #1 looks normal. #2 has a problem.
there are supposed to be images visible. but that means downloading them. i'm offline,
so i can't download them. what i can see is all the text that appears on the home
page. if that's enough for you, then you can browse offline. i can easily browse all the
text offline, but clearly there are limits.
 

Attachments

  • offline1.png
    46.6 KB · Views: 55
  • offline2.png
    55.8 KB · Views: 50
Upvote 0
Solution

alfaiz678

Active Member
Licensed User
Thank you very much I understood
any idea about working on the offline database and then synchronizing it when connected to the internet through the application ؟
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…