android - java.net.SocketException: socket failed: EACCES (Permission denied) -
i have searched solutions , applied project. not working. have permission denied.i have put possible permission manifest file. please tell me what's wrong project.
public static void getgetresponse() { inputstream inputstream = null; try { url url = new url("http://120.26.89.113:8080/common/qiniutoken"); httpurlconnection connection = (httpurlconnection)url.openconnection(); connection.setrequestmethod("get"); string userpassword = "wehelper:***********"; byte[] encodedbytes = base64.encode(userpassword.getbytes(), 0); connection.setrequestproperty("authorization", "basic " + encodedbytes); connection.connect(); int rescode = connection.getresponsecode(); if (rescode == 200) { inputstream = connection.getinputstream(); } bufferedreader reader = new bufferedreader(new inputstreamreader(inputstream)); stringbuilder out = new stringbuilder(); string line; while ((line = reader.readline()) != null) { out.append(line); } system.out.println(out.tostring());//prints string content read input stream log.d("myapp",out.tostring()); reader.close(); } catch (malformedurlexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } }
and manifest.xml
<application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsrtl="true" android:theme="@style/mymaterialtheme"> <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" /> <activity android:name=".mainactivity"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application>
logcat:
w/system.err: java.net.socketexception: socket failed: eacces (permission denied) w/system.err: @ libcore.io.iobridge.socket(iobridge.java:619) w/system.err: @ java.net.plainsocketimpl.create(plainsocketimpl.java:198) w/system.err: @ java.net.socket.checkopenandcreate(socket.java:689) w/system.err: @ java.net.socket.setsotimeout(socket.java:543) w/system.err: @ com.android.okhttp.internal.http.socketconnector.connectrawsocket(socketconnector.java:433) w/system.err: @ com.android.okhttp.internal.http.socketconnector.connectcleartext(socketconnector.java:105) w/system.err: @ com.android.okhttp.connection.connect(connection.java:1331) w/system.err: @ com.android.okhttp.connection.connectandsetowner(connection.java:1410) w/system.err: @ com.android.okhttp.okhttpclient$1.connectandsetowner(okhttpclient.java:128) w/system.err: @ com.android.okhttp.internal.http.httpengine.nextconnection(httpengine.java:466) w/system.err: @ com.android.okhttp.internal.http.httpengine.connect(httpengine.java:447) w/system.err: @ com.android.okhttp.internal.http.httpengine.sendrequest(httpengine.java:353) w/system.err: @ com.android.okhttp.internal.huc.httpurlconnectionimpl.execute(httpurlconnectionimpl.java:468) w/system.err: @ com.android.okhttp.internal.huc.httpurlconnectionimpl.connect(httpurlconnectionimpl.java:118) w/system.err: @ com.donghuaxue.spoonhunt.httpclient.getgetresponse(httpclient.java:44) w/system.err: @ com.donghuaxue.spoonhunt.mainactivity.oncreate(mainactivity.java:42) w/system.err: @ android.app.activity.performcreate(activity.java:6876) w/system.err: @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1135) w/system.err: @ android.app.activitythread.performlaunchactivity(activitythread.java:3207) w/system.err: @ android.app.activitythread.handlelaunchactivity(activitythread.java:3350) w/system.err: @ android.app.activitythread.access$1100(activitythread.java:222) w/system.err: @ android.app.activitythread$h.handlemessage(activitythread.java:1795) w/system.err: @ android.os.handler.dispatchmessage(handler.java:102) w/system.err: @ android.os.looper.loop(looper.java:158) w/system.err: @ android.app.activitythread.main(activitythread.java:7229) w/system.err: @ java.lang.reflect.method.invoke(native method) w/system.err: @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1230) w/system.err: @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1120) w/system.err: caused by: android.system.errnoexception: socket failed: eacces (permission denied) w/system.err: @ libcore.io.posix.socket(native method) w/system.err: @ libcore.io.blockguardos.socket(blockguardos.java:282) w/system.err: @ libcore.io.iobridge.socket(iobridge.java:604) w/system.err: ... 27 more
your <uses-permission>
elements in wrong place. need outside <application>
element, immediate children of 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>
Comments
Post a Comment