583

I am trying to access HTTP link using HttpURLConnection in Android to download a file, but I am getting this warning in LogCat:

WARN/System.err(223): java.net.SocketException: Permission denied (maybe missing INTERNET permission)

I have added android.Manifest.permission to my application but it's still giving the same exception.

3
  • Paste your manifest-permission contents, did you grant permissions for INTERNET? Commented Jan 30, 2010 at 20:22
  • 1
    i added import android.Manifest.permission; to app,nothing else. What else do i need to add to grant permissions
    – rob
    Commented Jan 30, 2010 at 20:27
  • 2
    Look at my answer below and see if that helps, and I have no idea what import android.Manifest.permission will do for you if you don't have INTERNET permission set in the AndroidManifest.xml file Commented Jan 30, 2010 at 20:27

13 Answers 13

1264

Assuming you do not have permissions set from your LogCat error description, here is my contents for my AndroidManifest.xml file that has access to the internet:

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

Other than that, you should be fine to download a file from the internet.

9
  • 4
    If you find answers that solve your question or seem helpful, its useful to select as "answered" and/or upvote, it helps out the community for anyone encountering the same problems. Thats not just directed to this question, but other questions you have asked also Commented Jan 30, 2010 at 20:31
  • i didn't knew about it, i will do that for sure if this will solve my problem
    – rob
    Commented Jan 30, 2010 at 20:32
  • report back if you encounter anything different and I will be more than happy to assist. Commented Jan 30, 2010 at 20:33
  • 1
    In my case I had to make sure it was the VERY FIRST line after the manifest statement.. anywhere below that and it would not work. v2.2, api level 8, htc g1
    – slf
    Commented Aug 20, 2011 at 22:01
  • 1
    @dialex AFAIK, there is no child element of uses-permission inside the application tag, only the manifest. Commented Mar 14, 2016 at 18:47
109

Permission name is CASE-SENSITIVE

In case somebody will struggle with same issue, it is case sensitive statement, so wrong case means your application won't get the permission.

WRONG

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

CORRECT

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

This issue may happen ie. on autocomplete in IDE

3
  • 1
    Thank you! I wasted my whole day wondering why my app was not working. I am new to android studio and this issue did not occur in Eclipse before :) Commented Jun 1, 2015 at 6:53
  • 3
    And I wasted my whole day figuring out what's actually difference between them, OMG its Capital and Small ANDROID.PERMISSION and android.permission ;) :p
    – fWd82
    Commented Jun 22, 2017 at 2:42
  • 2
    Documentation: developer.android.com/training/basics/network-ops/…
    – quant
    Commented Mar 8, 2019 at 5:53
65
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.photoeffect"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="com.example.towntour.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Black.NoTitleBar" >
    <activity
        android:name="com.photoeffect.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>
34

If you are using the Eclipse ADT plugin for your development, open AndroidManifest.xml in the Android Manifest Editor (should be the default action for opening AndroidManifest.xml from the project files list).

Afterwards, select the Permissions tab along the bottom of the editor (Manifest - Application - Permissions - Instrumentation - AndroidManifest.xml), then click Add... a Uses Permission and select the desired permission from the dropdown on the right, or just copy-paste in the necessary one (such as the android.permission.INTERNET permission you required).

26

FOR FLUTTER DEVELOPERS.

Go to

android/app/main/AndroidManifest.xml

Outside the

application tag

but inside the

manifest tag

Add

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

0
25

Copy the following line to your application manifest file and paste before the <application> tag.

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

Placing the permission below the <application/> tag will work, but will give you warning. So take care to place it before the <application/> tag declaration.

1
  • 1
    As of writing this comment, it goes outside of the application element but within the manifest. eg: <application> ... </application> <uses-permission android:name=" android.permission.INTERNET" /> </manifest> Commented Sep 16, 2017 at 11:53
16

Add the below line in your application tag:

 android:usesCleartextTraffic="true"

To be look like below code :

<application
    ....
    android:usesCleartextTraffic="true"
    ....>

And add the following tags above of application

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

to be like that :

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.themarona.app">
    <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:usesCleartextTraffic="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>
12

When using eclipse, Follow these steps

  1. Double click on the manifest to show it on the editor
  2. Click on the permissions tab below the manifest editor
  3. Click on Add button
  4. on the dialog that appears Click uses permission. (Ussually the last item on the list)
  5. Notice the view that appears on the rigth side Select "android.permission.INTERNET"
  6. Then a series of Ok and finally save.

Hope this helps

8

I am late but i want to complete the answer.

An permission is added in manifest.xml like

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

This is enough for standard permissions where no permission is prompted to the user. However, it is not enough to add permission only to manifest if it is a dangerous permission. See android doc. Like Camera, Storage permissions.

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

You will need to ask permission from user. I use RxPermission library that is widely used library for asking permission. Because it is long code which we have to write to ask permission.

RxPermissions rxPermissions = new RxPermissions(this); // where this is an Activity instance // Must be done during an initialization phase like onCreate
rxPermissions
    .request(Manifest.permission.CAMERA)
    .subscribe(granted -> {
        if (granted) { // Always true pre-M
           // I can control the camera now
        } else {
           // Oups permission denied
        }
    });

Add this library to your app

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

dependencies {
    implementation 'com.github.tbruyelle:rxpermissions:0.10.1'
    implementation 'com.jakewharton.rxbinding2:rxbinding:2.1.1'
}
4

That may be also interesting in context of adding INTERNET permission to your application:

Google has also given each app Internet access, effectively removing the Internet access permission. Oh, sure, Android developers still have to declare they want Internet access when putting together the app. But users can no longer see the Internet access permission when installing an app and current apps that don’t have Internet access can now gain Internet access with an automatic update without prompting you.

Source: http://www.howtogeek.com/190863/androids-app-permissions-were-just-simplified-now-theyre-much-less-secure/

Bottom line is that you still have to add INTERNET permission in manifest file but application will be updated on user's devices without asking them for new permission.

1

You have to use both Network and Access Network State in manifest file while you are trying load or access to the internet through android emulator.

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

If you are giving only .INTERNET permission, it won't access to the internet.

0
1

** For Activity Recognition like Foot Step Counter

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

** For Internet

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

** For Call Phone

<uses-permission android:name="android.permission.CALL_PHONE" />
[![enter image description here][1]][1]
0

If you're using Android Studio, hover over the code that requires the permission and click "Add Permission .."

enter image description here

Then you can check the changes in AndroidManifest.xml with git.

Not the answer you're looking for? Browse other questions tagged or ask your own question.