Tag Archives: SocketException sock

Developing in Android java.net.SocketException : socket failed: eacces (permission denied) reported an error

in the android development java.net.SocketException: socket failed: EACCES (Permission denied) error

knowledge point:

1, SocketException network operation error;

2. Solutions; (turned out to be a single user to close our app networking permissions, now new android system can be set for a permission)

today I met a user feedback, is that the problem encountered, click login, but unable to login, but prompt java.net.SocketException: socket failed: EACCES (Permission denied) this information. The first reaction is lack of network access, and then hurriedly check whether to join the network access.

adds

to the androidmanifest

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

However, I already wrote it in the program. It’s rare to write an Android app project that doesn’t connect to the Internet, so this should be included in the first place. So, this problem is eliminated. However, I found a lot of information, but did not find a suitable description and solution. It can’t be me.

so here are some of the possible reasons I’m looking for.

but I don’t have the user’s phone, otherwise the log error will be clear. Now you have to ask the user to download the app again. And then it’s OK. This is a real pain in the ass.

There’s a new possible issue: users have disabled your app’s access to the network. Notice that it’s a single block. So give your application access to the Internet based on the system.

For example, the operation of xiaomi mobile phone is: find the “security center” app, enter, and then see the “network assistant”, enter, and then click “network control”, find the corresponding app, check whether the corresponding “data” and “WLAN” options are hooked.

or

Java file network operation, add the following code

StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());

reason:

is most likely because the code for the possible network operation was written in the UI thread, which has not been allowed since android 4.0. Because network operations are done in the UI thread, if the network is bad then the whole program is easy to ANR. So android4.0 will have to open a new thread for code that wants to operate on the network.

or

network permissions are written like this:

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

instead of writing

<permission  android:name=“android.permission.INTERNET"></permission>

or

important – the uses-permission tag needs to be before the application tag in the manifest file. thats what fixed it for me at least.

outside the wall say: permissions to be in < application> Only when the tag is introduced can it work. (but I write that all the time, no problem) — get rid of

or

after you restart the ide, you can run the code normally again.

total reason:

lack of permissions?

permission error?

network operation in UI thread?

port occupation caused?

android version issues?

development tool problem?Restart and recompile