Adding internet permission to Android Project


If your application requires internet connection then you need to add permissions to the manifest file AndroidManifest.xml. If you don't do this then your app may crash throwing an exception.

Steps to Add Internet Permissions to Manifest file

Locate your AndroidManifest.xml file in your project folder,

AndroidManifest_xml.png
AndroidManifest_xml.png

Now you can see tabs at the lower side of the Manifest, click on Permissions,

Select Permissions.png
Select Permissions.png

Now click on "Add" to add a new element to manifest file.

Select User Permission,
Select Users Permission.png
Select Users Permission.png

Now you would see Name filed, select: android.permission.INTERNET, You can leave the Max SDK version as blank, but you can set a max API level as say 5.

Add android_permission_INTERNET.png
Add android_permission_INTERNET.png
Now if you see the XML view, you would see, <uses-permission android:name="android.permission.INTERNET" /> being added below user-sdk tag.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.internetEg"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />
    <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=".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>





      Topics: Pages | 2015 | Tutorials | Questions | Python