Android Webview Custom 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 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 with us Stack Overflow Questions Jobs Documentation android webview javascript Tags Users Badges 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;
Android Webview Xml
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 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. android webview chrome */ @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 // is loaded // Return the app name after finish loading if (progress == 100) MyActivity.setTitle(R.string.app_name); } }); }// EOM oc public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) { mWebView.goBack(); return true; } return super.onKeyDown(keyCode, event); } } I am trying to add onReceivedError but for some reason custom page is not loading. /** Called when the activity is first created. */ pu
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 user agent of this site About Us Learn more about Stack Overflow the company
Android Webview Update
Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges
Android Webview Stackoverflow
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: http://stackoverflow.com/questions/36284186/android-webview-custom-error-page Sign up Prevent WebView from displaying “web page not available” up vote 60 down vote favorite 19 I have an app that makes extensive use of a WebView. When the user of this app does not have Internet connection, a page saying "web page not available" and various other text appears. Is there a way to not show this generic text in http://stackoverflow.com/questions/6552160/prevent-webview-from-displaying-web-page-not-available my WebView? I would like to provide my own error handling. private final Activity activity = this; private class MyWebViewClient extends WebViewClient public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { // I need to do something like this: activity.webView.wipeOutThePage(); activity.myCustomErrorHandling(); Toast.makeText(activity, description, Toast.LENGTH_LONG).show(); } } I found out WebView->clearView doesn't actually clear the view. java android share|improve this question asked Jul 1 '11 at 18:58 JoJo 6,8722477138 2 Why don't you check the internet connection before showing the webView and if there is no internet facility available you can skip showing WebView and instead you can show an alert or toast with no internet message? –Andro Selva Jul 12 '11 at 10:03 @JoJo can you tick an answer as correct ? probably mine :P –Sherif elKhatib Aug 11 '11 at 0:29 add a comment| 12 Answers 12 active oldest votes up vote 70 down vote accepted First create your own error page in HTML and put it in your assets folder, Let's call it myerrorpage.html Then with onReceivedError: mWebView.setWebViewClient(new WebViewClient() { public void onReceivedError(WebView view, int errorCode, String descripti
{ @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { //To Prevent Web page not http://androiddubd.blogspot.com/2014/09/how-to-prevent-default-webview-error.html available if (errorCode == -2) { view.loadData("", "", null); //To Show Alert Dialog //SplashScreenActivity.class is the Launcher Activity // In Case of Frament instead of Activity Replace ClassName.this and getApplicationContext() with getActivity() AlertDialog.Builder builder = new AlertDialog.Builder(ClassName.this); builder.setCancelable(false); builder.setTitle(Html.fromHtml("Star Cineplex")); builder.setMessage(Html.fromHtml("Your data services are not android webview working.Please check your data services.")); builder.setPositiveButton(Html.fromHtml("OK"), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //SplashScreenActivity.class is your Launcher Activity // In Case of Fragment instead of Activity Replace getApplicationContext() with getActivity() Intent intent = new Intent(getApplicationContext(), SplashScreenActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra("EXIT", true); android webview custom startActivity(intent); } }); AlertDialog alert=builder.create(); alert.show(); Now at OnCreate of the Launcher Activity(eg. SplashScreenActivity.class) @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.loading_image_mn); //To exit if (getIntent().getBooleanExtra("EXIT", false)) { SplashScreenActivity.this.finish(); System.exit(0); } To Get: In Stead Of: Posted by Md Ilyas Hasan Mamun at 10:45 PM Email ThisBlogThis!Share to TwitterShare to FacebookShare to Pinterest Labels: Cancel Web Page Not Available, How To Prevent The Default WebView Error Page and Show Alert Dialog in Android, Remove Web Page Not Available Default WebView Error Page in Android 1 comment: Vitesh KotianJanuary 8, 2016 at 9:51 AMhello can i get source code for this..?ReplyDeleteAdd commentLoad more... Newer Post Older Post Home Subscribe to: Post Comments (Atom) About Me Md Ilyas Hasan Mamun View my complete profile Blog Archive ▼ 2014 (12) ▼ September (3) How To Refresh or Reload webpage automatically in ... How To Prevent The Default WebView Error Page and ... How to