---
title: "How to open url in our android application"  
description: "In this article I am explaining how to open url in our android application"  
author: "Manoj Pandey"  
published: 2015-03-19  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/1675/how-to-open-url-in-our-android-application  
category: "android"  
tags: ["android"]  
reading_time: 2 minutes  

---

# How to open url in our android application

Android’s WebView allows you to open an own windows for viewing URL or custom html markup page.\

URL handling on Android devices works through intents. Intents let apps register themselves to get launched in response to certain specified actions, and URL opening is one of these actions but if you want to open url within your project instead of browser then you have need WebView.

WebView is a view that displays [web pages](https://answers.mindstick.com/qa/95530/how-do-i-fix-safari-not-loading-web-pages). WebView class is the basis upon which you can roll your own [web browser](https://answers.mindstick.com/qa/95505/what-are-the-pros-and-cons-of-using-safari-web-browser) or simply display some online content within [your Activity](https://www.mindstick.com/interview/12746/the-last-callback-in-the-lifecycle-of-an-activity-is-ondestroy-the-system-calls-this-method-on-your-activity-as-the-final-signal-that-your-activity-instance-is-being-completely-removed-from-the-sys). It uses the WebKit rendering engine to display web pages and includes methods to navigate forward and backward through a history, zoom in and out, and perform text searches and more.

##### Here I am creating an example of webview which open site according to type

##### your url.

1. Create an android project.

2. Add [permission](https://answers.mindstick.com/qa/33390/how-to-enable-api-access-in-salesforce-by-permission-set) for using internet in your [AndroidManifest.xml file](https://www.mindstick.com/interview/2588/explain-androidmanifest-xml-file-in-detail)

```
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.androidwebview"    android:versionCode="1"    android:versionName="1.0" >     <uses-sdk        android:minSdkVersion="8"        android:targetSdkVersion="18" />     <uses-permission android:name="android.permission.INTERNET" />     <application        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >        <activity            android:name="com.example.androidwebview.MainActivity"            android:label="@string/app_name" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />             <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application> </manifest>
```

3. Add webview in activity_main.xml file

```
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context=".MainActivity" >     <EditText        android:id="@+id/urlField"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignTop="@+id/textView1"        android:layout_centerHorizontal="true"        android:ems="10" />     <Button        android:id="@+id/button1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_below="@+id/urlField"        android:layout_centerHorizontal="true"        android:onClick="open"        android:text="Browse" />     <WebView        android:id="@+id/webView1"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_alignLeft="@+id/textView1"        android:layout_alignParentBottom="true"        android:layout_below="@+id/button1" /> </RelativeLayout>
```

4. Add following code in MainActivity.class

```
package com.example.androidwebview; import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.view.View;import android.webkit.WebView;import android.webkit.WebViewClient;import android.widget.EditText; public class MainActivity extends Activity {                 private EditText field;                private WebView browser;                 @Override                protected void onCreate(Bundle savedInstanceState) {                                super.onCreate(savedInstanceState);                                setContentView(R.layout.activity_main);                                field = (EditText) findViewById(R.id.urlField);                                browser = (WebView) findViewById(R.id.webView1);                                browser.setWebViewClient(new MyBrowser());                }                 public void open(View view) {                                String url = field.getText().toString();                                url = "http://" + url;                                browser.getSettings().setLoadsImagesAutomatically(true);                                browser.getSettings().setJavaScriptEnabled(true);                                browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);                                // enabled javascript                                 browser.loadUrl(url);                                                 }                 private class MyBrowser extends WebViewClient {                                @Override                                // ignore browser                                public boolean shouldOverrideUrlLoading(WebView view, String url) {                                                view.loadUrl(url);                                                return true;                                }                }                 @Override                public boolean onCreateOptionsMenu(Menu menu) {                                // Inflate the menu; this adds items to the action bar if it is present.                                getMenuInflater().inflate(R.menu.main, menu);                                return true;                } }
```

Now run [your application](https://answers.mindstick.com/qa/95487/how-do-you-troubleshoot-when-your-application-link-is-not-responding)

![How to open url in our android application](https://www.mindstick.com/mindstickarticle/2967a400-7fe7-477d-beb5-65fc52474c32/images/7fcf4e0e-f336-4ddc-94dd-d77c61f4d7ce.png)

---

Original Source: https://www.mindstick.com/articles/1675/how-to-open-url-in-our-android-application

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
