Android में इंटरनेट अनुमति
Android ऐप में इंटरनेट एक्सेस के लिए <uses-permission android:name="android.permission.INTERNET" /> अनुमति आवश्यक है।
उदाहरण: WebView से Google खोलना
चरण 1: नया प्रोजेक्ट बनाएं
Android Studio में File → New Project से नया प्रोजेक्ट बनाएं।
चरण 2: लेआउट में WebView जोड़ें (activity_main.xml)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="https://schemas.android.com/apk/res/android"
xmlns:tools="https://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2dp"
tools:context=".MainActivity">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
चरण 3: MainActivity.java में URL लोड करें
import android.os.Bundle;
import android.webkit.WebView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true); // JavaScript सक्षम करें
webView.loadUrl("https://www.google.com");
}
}
चरण 4: AndroidManifest.xml में इंटरनेट अनुमति जोड़ें
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
package="com.example.internetpermission">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
ऐप चलाएं
डिवाइस कनेक्ट करें और Run दबाएं। ऐप लॉन्च होने पर Google का होम पेज WebView में खुलेगा।
