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
How to Add a Notification Badge/Count to Application Icon on Sony Xperia Devices
Accessing Sharedpreferences Through Static Methods
Help with Passing Arraylist and Parcelable Activity
Highlight Text in Textview or Webview
Changing the Android Overflow Menu Icon Programmatically
Shell Script in Android Gives [: Not Found
Get Database File in /Data/Data on Rooted Device
Android Device Not Shown with Adb
System Is Returning Error 127 When Called from C++ in Linux
Using "Printf" for Hex Values in Android Shell
Example Communicating with Handlerthread
How to Set Edittext to Only Accept Numeric Values in Android
Android Spinner:Avoid Onitemselected Calls During Initialization
Why Does the Google Play Store Say My Android App Is Incompatible with My Own Device
Is There Any Reason to Use the Support.V4 Library in Android
How to Maintain Multi Layers of Imageviews and Keep Their Aspect Ratio Based on the Largest One
Java.Lang.Illegalargumentexception: Contains a Path Separator