Android WebView Application Kaise Banaye?

Android WebView Ek Assan Rasta Kisi Bhi Website ya Blog ko Android App me Convert Karne Ka. Android Webview Upyog Hota hai Kisi bhi HTML Page Ko Display Karne ke Liye.

Aagar Aapko Abhi Webview ke Bare Nahi Pata To Aap Is Post Se Jaankari Hasil Kar Sakte hai.

Android WebView Kya hai?

Android WebView wah component hai Jiski Sahayata se Hum Kisi bhi HTML Page Ko Android App me Display Kar Sakte hai. Aap Ise Browser ki Trah Samajh Sakte hai. Aapne To embed Word Suna Hi Hoga. Jaise ki Hum Kisi bhi Website ko iFrame me Aapne HTML Page me Embed Kar Sakte hai. Waise hi Same Hum Android WebView me Kisi bhi HTML Page ko Embed karte hai.

Android WebView Example

Android Studio me Aap Ek New Project Bana Le. Jaise Aapka New Project Successfully Build Ho Jata hai to. Aapko Most Important 2 File Milti hai MainActivity.java and activity_main.xml Niche Diye code Ko Aap Aapne Project File activity_main.xml me Insert Kare.

♦ activity_main.xml

<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" 
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity">

<WebView

        android:id="@+id/webview"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</RelativeLayout>

Yah XML Code Kisi bhi HTML Page ko Android Application me Display Karne Me Sahayak hai. Is XML File me Humne WebView Component Insert Kiye hai Jaha ham Website ko Display Karayenge.

Aur Sath me Is Component ka Height & Width bhi aap Aapne According Customize Kar Sakte hai.Ab is XML file Ko MainActivity.java Se Connect karke Website ko Display Karenge. Jaise Humne Upper XML File me Ek Webview ID Create Kiye hai @+id/webview Is Id ke Sahare Hum MainActivity.java Ko Iske Sath Connect Karenge.

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

Android WebView loadUrl

Ek Bar Jab Humko WebView ka Reference Mil Jata hai. To Hum Isko Configure Kar Sakte hai. HTTP Method se URL ko Load Kara Sakte hai. webview loadUrl() Rules ka Use Karke WebView me URL ko Load Karne ke Liye Niche Code Diya gaya hai.

webView.loadUrl("https://www.wpwala.com");

Isse Pahle ki Hum URL ko Load Kare, iske 2 Important features hai Jinke Bare me Hame Janana Chahiye.:

1. Supporting JavaScript : Android Studio WebView Widget me JavaScript Default Band Hota hai. Jiske Karan Hum Jo Website Javascript ka Use Karta hai, Use Hum Sahi Tarike Se Display Nahi Kar Sakte hai. Kyo Humara WebView Javascript Support Nahi Karta.

JavaScript Support ko On Karne Ke Liye Simply Hum Is Code ka Use Karenge Jisse Hum Kisi Bhi Javascript Related Webiste ko Display Kar sakte hai.

getSettings().setJavaScriptEnabled(true);

2. Adding Permissions : Jaise Aap Ghar Se Kahi Jate hai to Aapko Aapne Parents se Permissions Lena Padta hai. Thik Usi Trah kisi bhi Component ko Start karne ke Liye Aapko Android Studio ko Permissions Magna Padta hai. Agar Aapne Android Studio se Aapke Component ke Liye Permission Nahi Liya to Jo Component Use Kar Rahe wah Work Nahi Karenga.

Jaisa Ki Hum Webview me Website ko Display Karenge Jiske Liye Hume Internet ki Jarurat Padegi. To Hume Internet Access Karne ki Permission Lena hoga. Jiska Setting Aap AndroidManifest.xml Se Kar Sakte hai Jaisa Niche Dikhaya Gaya hai

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wpwala.webview" >

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

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".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>

Abhi Tak Humne Jitna Bhi Uper Discussion Kiye hai. Uska Full Source MainAcvity.java me Samil Kiya Gaya hai. Jise Aap Aapne Project me Insert Kar Le. And Aap Jis URL ko Load Karana Chahte hai. Use Chenge Kar le.

MainActivity.java

package com.wpwala.webview;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

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

WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);

webView.loadUrl("https://www.wpwala.com");
}

}

WebViewClient ka Setting

WebView Successfully Run Hone ke Baad Website Display Hota hai. Agar Aap Website ke Kisi bhi Link me Click karte hai to Aapka Application Default Browser me Open Kar Deta hai.

Kyoki Abhi Aapne WebViewClient Setting Nahi Kiya hai. WebViewClient Aapke App ke Ander hi Website Link Ko Open karta hai. App is method se iska Setting Kar Sakte hai.

private class MyWebViewClient extends WebViewClient { 
@Override 
public boolean shouldOverrideUrlLoading(WebView webView, String url) { 
return false; 
} 
}

Yah Complete Tutorial Sayad Aapke Liye Helpful Ho. Agar Aapko Kahi Koi Pareshani Ata hai to Aap Comment karke puch Sakte hai.

I am a passionate and adroit Android Programmer. I like to learn new technologies and contribute new ideas and updates to an existing project. I enjoy Blogging too :).
Posts created 14

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top