683

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?

0

8 Answers 8

1451

Add the INTERNET permission to your manifest file.

You have to add this line:

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

outside (before) the application tag in your AndroidManifest.xml

Sign up to request clarification or add additional context in comments.

4 Comments

This tag should be placed BEFORE the aplication TAG. If you put if after aplication TAG, it produces a warning.
Restart the Emulator (was required for me before this would take effect).
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 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.
90

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> 

Comments

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

Comments

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> 

Comments

14

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

Comments

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.

Comments

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

1 Comment

ACCESS_WIFI_STATE is not required to access the internet. See, for example, developer.android.com/develop/connectivity/network-ops/…
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); } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.