Home > android webview > android webview replace error page

Android Webview Replace Error Page

Contents

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies android webview custom font of this site About Us Learn more about Stack Overflow the company Business

Android Custom Webview Class

Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges android webview example Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

Android Webview Javascript

Sign up How to edit or create custom error page for WebView? up vote 15 down vote favorite 5 I have created a WebView layout, which is used to access a specific website, however it would be useful to edit or create a custom "Web page not available" resource when a handset doesn't have a network connection or the page times out. I android webview xml know it's possible because if you open the app "Wikidroid" while a handset is in Airplane mode you receive "Article not available" error page instead of the standard Android "Web page not available" error page. I have search high and low on the internet and haven't come up with any online resources which address this request. Any and all help is much appreciated. Thanks in advance. android android-webview share|improve this question edited Jul 17 '15 at 5:01 Gopal Singh Sirvi 2,11541536 asked Nov 4 '10 at 21:00 Sid 6x 78115 add a comment| 2 Answers 2 active oldest votes up vote 18 down vote accepted To determine when the device has a network connection, request the permission and then you can check with the following code. First define these variables as class variables. private Context c; private boolean isConnected = true; In your onCreate() method initialize c = this; Then check for connectivity. ConnectivityManager connectivityManager = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager != null) { NetworkInfo ni = connectivityManager.getActiveNetworkInfo(); if (ni.getState() != NetworkInfo.State.CONNECTED) { // record the fact that there is not connection

here for a quick overview of the site Help Center

Android Webview Chrome

Detailed answers to any questions you might have Meta Discuss

Android Webview User Agent

the workings and policies of this site About Us Learn more about Stack Overflow the android webview update company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss http://stackoverflow.com/questions/4101331/how-to-edit-or-create-custom-error-page-for-webview Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Android webview custom error page up vote 0 down vote favorite I am creating application that use WebView to http://stackoverflow.com/questions/36284186/android-webview-custom-error-page access a online website. I am stuck where I have to add code to check availability of page. public class SpartanWeb extends Activity { WebView mWebView; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Adds Progrss bar Support this.getWindow().requestFeature(Window.FEATURE_PROGRESS); setContentView(R.layout.main); // Makes Progress bar Visible getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON); // Get Web view mWebView = (WebView) findViewById(R.id.webView1); WebSettings websettings = mWebView.getSettings(); websettings.setJavaScriptEnabled(true); mWebView.stopLoading(); mWebView.clearCache(true); mWebView.loadUrl("http://google.com"); mWebView.setHorizontalScrollBarEnabled(false); mWebView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); mWebView.setWebViewClient(new WebViewClient()); mWebView.setDownloadListener(new DownloadListener() { public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); startActivity(intent); } }); // onProgressChanged final Activity MyActivity = this; mWebView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { // bar disappear after URL is loaded, and changes string to // Loading... MyActivity.setTitle("Loading..."); MyActivity.setProgress(progress * 100); // Make the bar // disappear after URL

worked as-is (mainly, I had issues with the back-stack after implementing the more common suggestions), I came up with the following monstrosity. Use at your own peril: @Override public void onReceivedError(WebView webView, int errorCode, String description, String failingUrl) { try { webView.stopLoading(); } catch (Exception e) { } try { webView.clearView(); } catch (Exception e) { } if (webView.canGoBack()) { webView.goBack(); } webView.loadUrl("file:///android_asset/path/to/your/missing-page-template.html"); super.onReceivedError(webView, errorCode, description, failingUrl); } 12345678910111213141516 @Overridepublic void onReceivedError(WebView webView, int errorCode, String description, String failingUrl) { try { webView.stopLoading(); } catch (Exception e) { } try { webView.clearView(); } catch (Exception e) { } if (webView.canGoBack()) { webView.goBack(); } webView.loadUrl("file:///android_asset/path/to/your/missing-page-template.html"); super.onReceivedError(webView, errorCode, description, failingUrl);} the above is an overriden method of a new WebViewClient… e.g., private WebViewClient client = new WebViewClient() { // ... override whatever, including the onReceivedError method above } WebView webView = new WebView(context); webView.setWebViewClient(client); 12345 private WebViewClient client = new WebViewClient() {// ... override whatever, including the onReceivedError method above}WebView webView = new WebView(context);webView.setWebViewClient(client); Arun says: April 1, 2015 at 2:57 am You could avoid all those extra handling(stopLoading, clearView, goBack) by using webView.loadDataWithBaseURL which helps to overwrite the history. Reply moagrius says: April 1, 2015 at 7:41 am 404 is unlikely when working with pages constructed internally - this post details how to avoid the default 404 page shown when a page can't be loaded (almost certainly an external page). Thanks for posting. Reply Martin says: March 31, 2014 at 8:02 am Doesn't work on Android 4.1.2 Reply moagrius says: March 31, 2014 at 10:39 am What does "not work" mean exactly? Reply netdragon says: May 8, 2013 at 9:42 pm Doesn't work - Android 4.2 Reply gabriel says: November 8, 2012 at 6:57 am worked great! Reply moagrius says: November 8, 2012 at 8:17 pm HTH Reply Michael says: October 5, 2012 at 10:17 am SO F*** PERFECT! Thankyou very much!!! Reply moagrius says: October 5, 2012 at 11:21 am YW! Reply Tomer says: August 24, 2012 at 1:2

 

Related content

an error occurred while loading data in webview

An Error Occurred While Loading Data In Webview table id toc tbody tr td div id toctitle Contents div ul li a href Android Webview Onreceivederror a li li a href Android Webview Onreceivederror Not Called a li li a href Prevent Webview From Displaying web Page Not Available a li li a href Android Webview Check Internet Connection a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you might have relatedl Meta Discuss the workings and policies of this site About p h id Android

android onreceive error webview

Android Onreceive Error Webview table id toc tbody tr td div id toctitle Contents div ul li a href Android Webview Onreceivederror Not Called a li li a href Android Webview Error Handling a li li a href Android Webview Shouldoverrideurlloading a li li a href Android Webview Shouldinterceptrequest a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and relatedl policies of this site About Us Learn more about Stack p h id Android Webview Onreceivederror Not Called p

android onreceivederror error code

Android Onreceivederror Error Code table id toc tbody tr td div id toctitle Contents div ul li a href Android Webview Onreceivederror Not Called a li li a href Android Webview Error Handling a li li a href Android Onreceivederror Deprecated a li li a href Android Shouldinterceptrequest a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to relatedl any questions you might have Meta Discuss the workings p h id Android Webview Onreceivederror Not Called p and policies of this site About Us Learn more about Stack Overflow

android onreceivederror error codes

Android Onreceivederror Error Codes table id toc tbody tr td div id toctitle Contents div ul li a href Onreceivederror Deprecated a li li a href Android Webview Custom Error Page a li li a href Android Webview Error Handling a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions relatedl you might have Meta Discuss the workings and policies android webview onreceivederror not called of this site About Us Learn more about Stack Overflow the company p h id Onreceivederror Deprecated p Business Learn more about

android webview error loading page

Android Webview Error Loading Page table id toc tbody tr td div id toctitle Contents div ul li a href Android Webview Custom Error Page a li li a href Android Webview Loading Indicator a li li a href Android Webview Loading Too Slow a li li a href Android Webview Javascript a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to relatedl any questions you might have Meta Discuss the workings p h id Android Webview Custom Error Page p and policies of this site About Us Learn

android webview error handling 404

Android Webview Error Handling table id toc tbody tr td div id toctitle Contents div ul li a href Android Webview Url Catch a li li a href Android Webview Onreceivederror Deprecated a li li a href Android Webview Error a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you relatedl might have Meta Discuss the workings and policies of android webview error page this site About Us Learn more about Stack Overflow the company Business p h id Android Webview Url Catch p Learn more

android webview onreceivederror error codes

Android Webview Onreceivederror Error Codes table id toc tbody tr td div id toctitle Contents div ul li a href Android Webview Onreceivederror Not Called a li li a href Android Webview Error Handling a li li a href Android Onreceivederror Deprecated a li li a href Android Webviewclient Example a li ul td tr tbody table p p p here for a quick overview of the site Help Center Detailed answers to relatedl any questions you might have Meta Discuss the android webview shouldoverrideurlloading workings and policies of this site About Us Learn more about Stack p h id

android webview http error codes

Android Webview Http Error Codes table id toc tbody tr td div id toctitle Contents div ul li a href Android Webview Source Code a li li a href Android Webview Xml a li li a href Android Webview Chrome a li li a href Android Webview Update a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you might relatedl have Meta Discuss the workings and policies of this site p h id Android Webview Source Code p About Us Learn more about Stack Overflow the

android webview hide error page

Android Webview Hide Error Page table id toc tbody tr td div id toctitle Contents div ul li a href Android Webview Disable Cache a li li a href Android Webview Example a li li a href Android Webview Xml a li li a href Android Webview Chrome a li ul td tr tbody table p here for a quick overview of the site Help Center relatedl Detailed answers to any questions you might have android webview disable scrolling Meta Discuss the workings and policies of this site About Us p h id Android Webview Disable Cache p Learn more

android webview error page

Android Webview Error Page table id toc tbody tr td div id toctitle Contents div ul li a href Android Webview Chrome a li li a href Android Webview Stackoverflow a li li a href Android Webview Javascript Interface a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and relatedl policies of this site About Us Learn more about Stack android webview example Overflow the company Business Learn more about hiring developers or posting ads with us android webview

android webview custom error page

Android Webview Custom Error Page table id toc tbody tr td div id toctitle Contents div ul li a href Android Webview Xml a li li a href Android Webview Update a li li a href Android Webview Stackoverflow a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to relatedl any questions you might have Meta Discuss the workings android webview custom font and policies of this site About Us Learn more about Stack Overflow android webview example the company Business Learn more about hiring developers or posting ads

android webview 404 error

Android Webview Error table id toc tbody tr td div id toctitle Contents div ul li a href Android Webview Example a li li a href Android Webview Xml a li li a href Android Webview User Agent a li li a href Android Webview Update a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you relatedl might have Meta Discuss the workings and policies of android webview error page this site About Us Learn more about Stack Overflow the company Business Learn p h id

android webview server error

Android Webview Server Error table id toc tbody tr td div id toctitle Contents div ul li a href Android Webview Example a li li a href Android Webview Chrome a li li a href Android Webview User Agent a li li a href Android Webview Stackoverflow a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers relatedl to any questions you might have Meta Discuss p h id Android Webview Example p the workings and policies of this site About Us Learn more android webview javascript about Stack Overflow

android webview error codes

Android Webview Error Codes table id toc tbody tr td div id toctitle Contents div ul li a href Android Webview Source Code a li li a href Android Webview Javascript a li li a href Android Webview User Agent a li li a href Android Webview Stackoverflow a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions relatedl you might have Meta Discuss the workings and policies p h id Android Webview Source Code p of this site About Us Learn more about Stack Overflow the

android webview catch javascript error

Android Webview Catch Javascript Error table id toc tbody tr td div id toctitle Contents div ul li a href Android Webview Javascript Callback a li li a href Android Webview Javascript Enable a li li a href Android Webview Javascript Console a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings relatedl and policies of this site About Us Learn more about android webview javascript not working Stack Overflow the company Business Learn more about hiring developers or posting

android webview catch 404 error

Android Webview Catch Error table id toc tbody tr td div id toctitle Contents div ul li a href Android Webview Detect Redirect a li li a href Onreceivedhttperror a li li a href Android Webview Onreceivederror Example a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies relatedl of this site About Us Learn more about Stack Overflow android webview url catch the company Business Learn more about hiring developers or posting ads with us Stack Overflow

android webview network error

Android Webview Network Error table id toc tbody tr td div id toctitle Contents div ul li a href Android Webview Javascript a li li a href Android Webview User Agent a li li a href Android Webview Javascript Interface a li ul td tr tbody table p here for a quick overview of the site relatedl Help Center Detailed answers to any questions android webview example you might have Meta Discuss the workings and policies of this p h id Android Webview Javascript p site About Us Learn more about Stack Overflow the company Business Learn more about hiring

android webview override error page

Android Webview Override Error Page table id toc tbody tr td div id toctitle Contents div ul li a href Android Custom Webview Class a li li a href Android Webview Onreceivederror Not Called a li li a href Android Webview Onreceivederror Deprecated a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta relatedl Discuss the workings and policies of this site About android webview custom font Us Learn more about Stack Overflow the company Business Learn more about hiring p h id