Android Apps

How to get url not reached error in Anodroid Phonegap

June 1, 2012 by Sarath DR in Android Apps, Featured with 5 Comments

It was very tricky to find out this solution and have spent a lots of time on it. I feel it is very useful when you are developing an Android web app. For example if your server is not responding to the request or if there is no network connectivity, webviewClient will trigger the function onReceivedError and if it is not caught properly it will close application.

You have to override the onReceivedError function in onCreate. Actually you can handle it very nicely by the following two steps.

Step 1: Create an html page in your /assets/www/ folder with proper no connectivity message. I have created noConnection.html in the folder

Step 2: Add the following java code in your App Class which extends DroidGap

        public void onReceivedError( int errorCode, String description, String failingUrl)
	{
		super.loadUrl("file:///android_asset/www/noConnection.html");
		return;
 
	}

As per the request I am updating the whole java file.

 
 
import android.os.Bundle;
import android.webkit.*;
import org.apache.cordova.*;
import com.phonegap.ringtagz.CustomNativeAccess;
import android.content.pm.ActivityInfo;
 
public class App extends DroidGap {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
 
        super.init();
        super.clearCache();
 
        CustomNativeAccess cna = new CustomNativeAccess(this, appView);    
        appView.addJavascriptInterface(cna, "CustomNativeAccess");
 
 
        super.setIntegerProperty("splashscreen", R.drawable.splash);
        super.loadUrl("file:///android_asset/www/index.html");
        // super.loadUrl("file:///android_asset/www/index_test.html");
 
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
 
    }
 
        public void onReceivedError( int errorCode, String description, String failingUrl)
	{
		super.loadUrl("file:///android_asset/www/noConnection.html");
		return;
 
	}
 
 }

Tagged , , ,

Share this to

Related Posts

5 Comments

  1. lsJun 13, 2012 at 1:25 pmReply

    Can you post your whole .java file?

    • adminJun 14, 2012 at 6:41 pmReplyAuthor

      Hi Sorry for the late reply. I have updated the post

  2. Steps to Convert a web app into Android Phonegap AppJul 21, 2012 at 10:59 pmReply

    [...] Step 6: To catch the loading error over write the onReceived error in the following way [...]

  3. Steps to Convert a web app into Android Phonegap App | Programmer BlogAug 6, 2013 at 9:03 amReply

    [...] Step 6: To catch the loading error over write the onReceived error in the following way [...]

  4. Steps to Convert a web app into Android Phonegap App | Web DeveloperFeb 6, 2014 at 1:03 pmReply

    [...] Step 6: To catch the loading error over write the onReceived error in the following way [...]

Leave a reply

Your email address will not be published. Required fields are marked *

*

About
View Sarath D R's profile on LinkedIn

I am a technology consultant and an entrepreneur focused on the following technologies Java,Spring, Android, Angular, Asterisk, Symfony, Cake , Code-Igniter, Jquery , XAMPP, XHTML, AJAX, MySql, Seo, Web Design, Wordpress, iPhone development.

Today’s Tips
  • Generate Codova.jar file from Phonegap project using ant
  • Google map javascript client  to find the geographic co-ordinates  from  Address or post code
  • Update Android main UI from Webview – Phonegap Plugin
  • Jplayer is not working  with HTC One Android 4.3 version browser
  • Regular expression to validate mobile phone numbers starting with + ( plus ) – php
  • Simple pagination script for PHP
  • Useful adb ( Android Debug Bridge ) commands
  • Change the javascript files url to absolute url – Symfony 1.4
  • Set Http authentication header from Client – PHP / CURL

This site uses cookies from Google to deliver its services, to personalise ads and to analyse traffic. Information about your use of this site is shared with Google. By using this site, you agree to its use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.This site also uses cookies from Google to deliver its services, to personalise ads and to analyse traffic. Information about your use of this site is shared with Google. By using this site, you agree to its use of cookies.

Close