I show a website in a webview. I want now to show at first a blank screen with a logo at the top and a text "Checking Internet Connection". When the connection is available, then I show the website in a webview. Later when the internet connection failed, I want to show the same blank screen with the logo and the Text "Checking Internet Connection and trying to connect".
Asked
Active
Viewed 1,167 times
2
-
1You aren't actually thinking of busy-waiting until the network becomes available, are you? That will kill the user's battery. You need to register a receiver for a connectivity change event. http://stackoverflow.com/questions/3767591/check-intent-internet-connection – David Conrad Mar 12 '12 at 10:38
-
Thanks to all. Receiver is, what i need. – user1205415 Mar 13 '12 at 08:24
1 Answers
1
before actually show the webview content, you can
WebView.loadUrl (String url)
the url can be local file in /assets
folder, you can use a simple html which like your
a blank screen with a logo at the top and a text "Checking Internet Connection
updating:
step1 :check the internet, this is you can control
step2: try to load actually website,
WebView.setWebViewClient(new WebViewClient(...))
in your WebViewClient
class , override method
public void onReceivedError (WebView view, int errorCode, String description, String failingUrl)
when receive error, you can WebView.loadUrl(...)

idiottiger
- 5,147
- 2
- 25
- 21
-
But when i in onReceivedError, i show the website, and thats it. This don't make a new connection check. Or is that so, that when i have a connection im going from onReceivedError to "public boolean shouldOverrideUrlLoading"? – user1205415 Mar 12 '12 at 08:52
-
ye, `onReceivedError` also show the http error page. can you try this: make a thread to request using `HttpClient.execute (HttpUriRequest request)` to check the response form server, if the response code is right( like 200 ),actually to load the url, otherwise load your custom html file? – idiottiger Mar 12 '12 at 09:05
-
1