问题
I'm running the following test Java script from the Android HttpURLConnection docs:
URL url = new URL("http://www.android.com/");
HttpURLConnection urlConnection = (HttpURLConnection)
url.openConnection();
urlConnection.connect();
Eclipse (on my Mac) is telling me there's a system error when I run this in the Android Emulator:
01-13 13:44:32.767: WARN/System.err(1382): java.net.SocketException: Permission denied
(Incidentally when I do the equivalent in Objective-C/Cocoa there's no problem at all.)
What is the problem?
回答1:
Your application is not allowed to access the network unless it has declared that its going to in the AndroidManifest.xml file, add this inside the <manifest>
element.
<uses-permission android:name="android.permission.INTERNET" />
来源:https://stackoverflow.com/questions/4676897/android-httpurlconnection-error