Error Message 'Java.Net.Socketexception: Socket Failed: Eacces (Permission Denied)'

java.net.SocketException: socket failed: EACCES (Permission denied)

Your <uses-permission> elements are in the wrong place. They need to be outside the <application> element, as immediate children of the root <manifest> element:

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

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/MyMaterialTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

Android java.net.SocketException:socket failed: EACCES (Permission denied)

Try adding the following:

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

W/System.err: java.net.SocketException: socket failed: EACCES (Permission denied) in android

Your app is running on an emulator. If your app uses localhost address 127.0.0.1 it tries to connect to a server also running on that emulator.

If your server is running on the same pc your emulator is running on your app should use ip address 10.0.2.2 instead.

java.net.SocketException: socket failed: EACCES (Permission denied) not solved by uses-permission

Quoting myself:

The <uses-permission> elements should be inside the <manifest>
element, but outside the <application> element. In other words, this
is fine:

<?xml version="1.0" encoding="utf-8"?>
<manifest
package="com.commonsware.android.something.something"
xmlns:android="http://schemas.android.com/apk/res/android">

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

<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">

<!-- cool stuff goes here -->

</application>

</manifest>

but this is not:

<?xml version="1.0" encoding="utf-8"?>
<manifest
package="com.commonsware.android.something.something"
xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">

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

<!-- cool stuff goes here -->

</application>

</manifest>

While Android Studio will report this if you manually analyze your
manifest (Analyze > Inspect Code... from the main menu), it will not
automatically show a warning just by having the elements in the
wrong spot.



Related Topics



Leave a reply



Submit