669

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Janusz
  • 187,060
  • 113
  • 301
  • 369

15 Answers15

1410

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

Mahesh Jamdade
  • 17,235
  • 8
  • 110
  • 131
Nikola Smiljanić
  • 26,745
  • 6
  • 48
  • 60
  • 64
    This tag should be placed BEFORE the aplication TAG. If you put if after aplication TAG, it produces a warning. – Marek Jun 06 '13 at 01:58
  • 3
    Restart the Emulator (was required for me before this would take effect). – jcalfee314 Dec 14 '13 at 23:44
  • 1
    I have problem. I don't want access to internet for my apk. No permission added to manifest, but if i try to install apk, installation inform me, that apk need FULL INTERNET ACCESS. How to solve this problem ? no permissions added to manifest. My apk not required full internet access - i want disable this permision. – Altivo Feb 25 '15 at 13:48
  • 1
    @Altivo Look at your merged manifest in ../app/build/intermediates/manifests/full/debug/AndroidManifest.xml. Here you will find all the permissions that your app uses. This is formed by merging your app's manifest as well as the used libraries' manifests. You must have mostly used the google play services library, which contains INTERNET and ACCESS_NETWORK_STATE permissions. – Sid Aug 11 '16 at 03:40
130

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" /> 
Finley Smith
  • 1,599
  • 2
  • 11
  • 15
  • 2
    Any reference to a Google document where it says so? – farindk Aug 28 '14 at 23:56
  • @farindk the first note section here: https://support.google.com/googleplay/answer/6014972?hl=en – Finley Smith Nov 03 '14 at 19:23
  • 28
    The document you link to talks about how the Play Store will not include the Internet permission in the primary list of permissions that it displays to the user when asking whether to install an app. It *doesn't* say that an app that uses the Internet no longer needs to declare that it does so in its manifest's list of used permissions. Do you mean to say that *all* apps *implicitly* use the Internet without saying so in their manifests? That is, if Janusz ran the same app from the question in *today's* phones, it would *not* have failed the way it did when the question was asked? – Rob Kennedy Jan 19 '15 at 23:53
  • 2
    If you refer the [permission docs](https://developer.android.com/reference/android/Manifest.permission.html#INTERNET) you'll see that it isn't deprecated. Deprecated permissions are permissions that aren't used, that you don't need to have in your manifest because they aren't used anymore. Unused permissions can be because the API was replaced, or because it isn't needed anymore. So yeah, you need the internet permission to access the internet. Even the basic docs on connecting to the internet also state that the internet permission is required. – Zoe Oct 28 '17 at 19:41
  • https://developer.android.com/training/basics/network-ops/connecting#java – Suragch Jun 11 '19 at 19:21
88

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>

Kirtikumar A.
  • 4,140
  • 43
  • 43
52
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
AndroidDev
  • 15,993
  • 29
  • 85
  • 119
  • do you know of any other permissions that might be required to allow NTLM/Windows Authentication? Especially in a XenMobile environment...just throwing a dart here.. – whyoz Oct 09 '15 at 15:40
16

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:

<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>
Amy
  • 4,034
  • 1
  • 20
  • 34
11

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

Jedsada Saengow
  • 211
  • 4
  • 6
8

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.

Akshay Paliwal
  • 3,718
  • 2
  • 39
  • 43
7

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" />
Olorunfemi Davis
  • 1,001
  • 10
  • 23
6

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);
    }
Vaibhav Joshi
  • 145
  • 1
  • 5
5

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

AG-Developer
  • 361
  • 2
  • 10
4

Just put below code in AndroidManifest :

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

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"/>
Kashif Faraz Shamsi
  • 513
  • 1
  • 7
  • 21
3

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

trustidkid
  • 577
  • 4
  • 6
3

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"/>
Kanwarpreet Singh
  • 2,037
  • 1
  • 13
  • 28
-1

add this two code before the <android ... inside the manifest file

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Azizur Rahaman
  • 181
  • 2
  • 5