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>



Recent Posts:




Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.