What permission do I need to access Internet from an Android application?

AndroidAndroid Permissions

Android Problem Overview


I get the following Exception running my app:

java.net.SocketException: Permission denied (maybe missing INTERNET permission)

How do I solve the missing permission problem?

Android Solutions


Solution 1 - Android

Add the INTERNET permission to your manifest file.

You have to add this line:

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

outside the application tag in your AndroidManifest.xml

Solution 2 - Android

In the latest release of Google Play, Google removed the need to ask permission for internet as "most apps need it anyways nowadays". However, for users who have older versions, it is still recommended to leave the code below in your manifest

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

Solution 3 - Android

just put above line like below

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.avocats.activeavocats"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="9"
    android:targetSdkVersion="16" />

 <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="com.example.exp.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>

Solution 4 - Android

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

Solution 5 - Android

If you want using Internet in your app as well as check the network state i.e. Is app is connected to the internet then you have to use below code outside of the application tag.

For Internet Permission:

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

For Access network state:

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

Complete Code: http://schemas.android.com/apk/res/android" package="com.example.myapp" android:versionCode="1" android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="9"
    android:targetSdkVersion="16" />

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

<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>

Solution 6 - Android

if just using internet then use-

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

if you are getting the state of internet then use also -

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

just above the application tag.

Solution 7 - Android

I had the same problem even use <uses-permission android:name="android.permission.INTERNET" />

If you want connect web api using http not https. Maybe you use android device using Android 9 (Pie) or API level 28 or higher . android:usesCleartextTraffic default value is false. You have to set be

<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        ...
        android:usesCleartextTraffic="true" <!-- this line -->
        ...>
           ...
    </application>
</manifest>

Finally, should be https

https://developer.android.com/guide/topics/manifest/application-element#usesCleartextTraffic

Solution 8 - Android

Use these:

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

Solution 9 - Android

forget about adding the permission into the manifest Add this code as a method

public static boolean hasPermissions(Context context, String... permissions)
{
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null && permissions != null)
    {
        for (String permission : permissions)
        {
            if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED)
            {
                return false;
            }
        }
    }
    return true;
}

and write this in your Main

int PERMISSION_ALL = 1;
    String[] PERMISSIONS = {Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_SMS, Manifest.permission.CAMERA};

    if (!hasPermissions(this, PERMISSIONS)) {
        ActivityCompat.requestPermissions(this, PERMISSIONS, PERMISSION_ALL);
    }

Solution 10 - Android

Just Add these 2 permissions

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

in your app's AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.android.networkusage"
        ...>
    
    
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    
        <application 
            ...>
            ...
        </application>
    </manifest>

Happy Coding:)

Solution 11 - Android

Just put below code in AndroidManifest :

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

Solution 12 - Android

As per current versions, Android doesn't ask for permission to interact with the internet but you can add the below code which will help for users using older versions Just add these in AndroidManifest

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

Solution 13 - Android

To request for internet permission in your code you must add these to your AndroidManifest.xml file

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

For more detail explanation goto https://developer.android.com/training/basics/network-ops/connecting

Solution 14 - Android

Google removed the need to ask permission for the internet for the latest version. Still, to request for internet permission in your code you must add these to your AndroidManifest.xml file.

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJanuszView Question on Stackoverflow
Solution 1 - AndroidNikola SmiljanićView Answer on Stackoverflow
Solution 2 - AndroidFinley SmithView Answer on Stackoverflow
Solution 3 - AndroidKirtikumar A.View Answer on Stackoverflow
Solution 4 - AndroidAndroidDevView Answer on Stackoverflow
Solution 5 - AndroidAmyView Answer on Stackoverflow
Solution 6 - AndroidAkshay PaliwalView Answer on Stackoverflow
Solution 7 - AndroidJedsada SaengowView Answer on Stackoverflow
Solution 8 - AndroidOlorunfemi DavisView Answer on Stackoverflow
Solution 9 - AndroidVaibhav JoshiView Answer on Stackoverflow
Solution 10 - AndroidAG-DeveloperView Answer on Stackoverflow
Solution 11 - AndroidHiren GondaliyaView Answer on Stackoverflow
Solution 12 - AndroidKashif Faraz ShamsiView Answer on Stackoverflow
Solution 13 - AndroidtrustidkidView Answer on Stackoverflow
Solution 14 - AndroidKanwarpreet SinghView Answer on Stackoverflow