Android Tutorials - Herong's Tutorial Examples - Version 3.00, by Dr. Herong Yang

android.webkit.WebView - Web Browser Base Class

This section provides a tutorial example on how to create an Android project to build your own Web browser using the android.webkit.WebView class. The first version failed with 'Webpage not available' error.

Android SDK offers a nice view class, android.webkit.WebView, that helps you to build your version of a Web browser. Here is my first version of AndroidWeb application:

Create AndroidWeb project with the "android create project" command:

C:\herong>\local\android-sdk-windows\tools\android create project \
   -k com.herongyang.web -a AndroidWeb -t 2 -p .\AndroidWeb

Edit the activity class Java code stored at \herong\AndroidWeb\src\com\herongyang\web\AndroidWeb.java:

/* AndroidWeb.java
 * Version 1.0 - Show Google home page
 * Copyright (c) 2015, HerongYang.com, All Rights Reserved.
 */
package com.herongyang.web;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class AndroidWeb extends Activity {
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      WebView view = new WebView(this);
      view.loadUrl("http://www.google.com/");
      setContentView(view);
   }
}

Build the debug package and install it to the emulator using the "ant" command:

C:\herong\AndroidWeb>\local\apache-ant-1.8.3\bin\ant debug

C:\herong\AndroidWeb>\local\apache-ant-1.8.3\bin\ant installd

Run AndroidWeb on the emulator. Too bad. AndroidWeb 1.0 is not working. The following message is showing on the screen:

Webpage not available

The webpage at http://www.google.com/ could not be loaded because: 

net:ERR_CACHE_MISS
AndroidWeb Webpage not available Error
AndroidWeb Webpage not available Error

The error is not very helpful. I will try to find the root cause in the next tutorial.

By the way, the same program running in Android SDK R17 gave the following error message:

Webpage not available

The webpage at http://www.google.com/ might be temporarily down or
it may have moved permanently to a new web address. 

Suggestions: 
   Make sure you have a data connection
   Reload this webpage later
   Check the address you entered

Last update: 2015.

Table of Contents

 About This Book

 Installing JDK 1.8 on Windows System

 Installation of Android SDK R24 and Emulator

 Installing Apache Ant 1.9 on Windows System

 Developing First Android Application - HelloAndroid

 Android Application Package (APK) Files

 Android Debug Bridge (adb) Tool

 Android File Systems

 Android 4.0.3 File Systems

 AboutAndroid - Application to Retrieve System Information

 android.app.Activity Class and Activity Lifecycle

 View Objects and Layout Resource Files

 Using "adb logcat" Command for Debugging

 Build Process and Package File Content

Building Your Own Web Browser

android.webkit.WebView - Web Browser Base Class

 AndroidWeb - My Own Web Browser

 WebViewClient Subclass - Content Rendering Callbacks

 saveWebArchive() Method - Saving Web Archive Files

 Web Archive File - XML File of Base64 Encoded Data

 Android Command Line Shell

 Samsung Galaxy Tab 3 Mini Tablet

 USB Debugging Applications on Samsung Tablet

 Android Tablet - LG-V905R

 USB Debugging Applications on LG-V905R Tablet

 Android Phone - LG-P925g

 USB Debugging Applications on LG-P925g Phone

 Outdated Tutorials

 References

 PDF Printing Version

Building Your Own Web Browser - Updated in 2015, by Dr. Herong Yang