Monday, June 18, 2012

Web View In Android

This is a sample activity which shows How to invoke web browser from your application.
Underlying Algorithm:
Basic description of algorithm in step by step form:
1.) Create a Project WebViewDemo.
2.) Add the relevant permissions to your AndroidManifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""

    <uses-sdk android:minSdkVersion="11" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".WebViewDemo" android:label="@string/app_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
3.) Put the following code snippet in main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
4.) Run the application.
Steps to Create:
1.) Open Eclipse. Use the New Project Wizard and select Android Project. Give the respective project name i.e. WebViewDemo. Enter following information:
Project name: WebViewDemo
Build Target: Google APIs
Application name: WebViewDemo
Package name: com.sample.WebViewDemo
Create Activity: WebViewDemo
On Clicking Finish WebViewDemo code structure is generated with the necessary Android Packages being imported along with WebViewDemo class will look like following:
package com.sample.WebViewDemo;
import android.os.Bundle;
import android.webkit.WebView;
public class WebViewDemo extends Activity {
        /** Called when the activity is first created. */
        public void onCreate(Bundle savedInstanceState) {
                WebView webView = (WebView) findViewById(;
Output –The final output:

No comments:

Post a Comment