Logo Icon Logo
A Crowd-sourced Cookbook on Writing Great Android® Apps
GitHub logo Twitter logo OReilly Book Cover Art

Accessing a Web Page Using WebView

In Chapter: Networked Applications
Author: Rachee Singh ('racheesingh')
Published? true
FormatLanguage: WikiFormat


Opening a website within your application.


Embed a WebView component in the layout and use it to display the web page.


In the application, since we wish to access a web page, we need to add the Internet permission into the manifest file:

<uses-permission android:name="android.permission.INTERNET" />

The component which is used to display a web page within an application is called a WebView. We add a WebView to the XML layout:


In the Java code for the activity that displays the web page, we obtain a handle onto the WebView using findViewById() method. On the WebView we use the loadUrl method to provide it the URL of the web site we wish to open in the application.

WebView webview = (WebView)findViewById(R.id.webview);


The source code for this project can be downloaded from https://docs.google.com/leaf?id=0B_rESQKgad5LN2JhMDFjZTUtY2IwZS00NzkyLWFlNjItMzhiZWRlYTQxMWNm&hl=en_US .