A browser is an application program that provides a way to look at and interact with all the information on the World Wide Web. The word "browser" seems to have originated prior to the Web as a generic term for user interfaces that let you browse (navigate through and read) text files online.
Many Application in Android Comes with inbuilt Browser to open URL(Uniform Resource Locator) to give a better User experience to user this also helps to protect user to navigate different apps.This helps in spending more time by the user into an app without distraction with good User experience.

For More Tutorial Share And Subscribe to my Blog So you will get all the updates on your email, We Never Spam.
Thank You
Many Application in Android Comes with inbuilt Browser to open URL(Uniform Resource Locator) to give a better User experience to user this also helps to protect user to navigate different apps.This helps in spending more time by the user into an app without distraction with good User experience.
So In this tutorial, we will see how to Work with WebView and Load and pass the Url into the webview And How to get the title of the Loaded Page.
So guys Lets Start,
1. Create a new project by going to File ⇒ New Android Project. Fill all the details and name your activity as MainActivity.
2. Once the project is created open your activity_main.xml file and Add Below Code.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.targetandroid.info.mybrowser.MainActivity"> <TextView android:id="@+id/tv_webtitle" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:textSize="20sp" android:textColor="#000000" android:background="#fff" android:layout_marginBottom="10dp"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <EditText android:id="@+id/et_url" android:layout_width="300dp" android:layout_height="wrap_content" android:lines="1" android:hint="enter web address"/> <Button android:id="@+id/bt_go" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="go"/> </LinearLayout> <WebView android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" /> </LinearLayout>
3. Add an Internet Permission into AndroidManifest.xml , because here we need to use the Internet so Permission of Internet is Mandatory.
type this line Above Application Tag to Access Internet
type this line Above Application Tag to Access Internet
<uses-permission android:name="android.permission.INTERNET"/>
4. Now open your Main Activity.java
import android.app.ProgressDialog; import android.graphics.Bitmap; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.text.TextUtils; import android.view.View; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class MainActivity extends AppCompatActivity { WebView webView; String PageURL, pageTitle; TextView tv_webtitle; EditText et_url; Button bt_go; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); webView=(WebView)findViewById(R.id.webview); tv_webtitle=(TextView)findViewById(R.id.tv_webtitle); et_url=(EditText)findViewById(R.id.et_url); bt_go=(Button)findViewById(R.id.bt_go); //To open links clicked by the user, simply provide a WebViewClient for your WebView webView.setWebViewClient(new WebClient()); bt_go.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //checking if url is not Empty or null if (!TextUtils.isEmpty(et_url.getText().toString())) { //load url into webview webView.loadUrl("http://"+et_url.getText().toString()); } } }); } public class WebClient extends WebViewClient{ @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); //get the url which we redirect and Title of that Web page et_url.setText(view.getUrl()); tv_webtitle.setText(view.getTitle()); } } }
5. Now finally run your Project you will see a Below Output


Thank You
EmoticonEmoticon