我正在尝试从我的android应用程序下载网络内容。但是每当我跑步时,我都会遇到以下问题。我在Mac上使用的是Android Studio 3.5.1。
这是一些代码。
protected String doInBackground(String... urls) {
String result = "";
URL url;
HttpURLConnection httpURLConnection= null;
try {
url = new URL(urls[0]);
httpURLConnection = (HttpURLConnection) url.openConnection();
InputStream inputStream = httpURLConnection.getInputStream();
InputStreamReader reader = new InputStreamReader(inputStream);
int data = reader.read();
while (data != -1){
char current = (char) data;
result += current;
data = reader.read();
}
return result;
} catch (Exception e) {
e.printStackTrace();
return "Failed";
}
}
以下是错误代码:
2019-11-04 23:43:52.801 19692-19692/? I/nloadwebconten: Not late-enabling -Xcheck:jni (already on)
2019-11-04 23:43:52.870 19692-19692/? E/nloadwebconten: Unknown bits set in runtime_flags: 0x8000
2019-11-04 23:43:52.872 19692-19692/? W/nloadwebconten: Unexpected CPU variant for X86 using defaults: x86
2019-11-04 23:43:53.355 19692-19721/com.example.downloadwebcontent D/libEGL: Emulator has host GPU support, qemu.gles is set to 1.
2019-11-04 23:43:53.340 19692-19692/com.example.downloadwebcontent W/RenderThread: type=1400 audit(0.0:147): avc: denied { write } for name="property_service" dev="tmpfs" ino=840 scontext=u:r:untrusted_app:s0:c136,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0
2019-11-04 23:43:53.356 19692-19721/com.example.downloadwebcontent W/libc: Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied)
2019-11-04 23:43:53.386 19692-19721/com.example.downloadwebcontent D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
2019-11-04 23:43:53.406 19692-19721/com.example.downloadwebcontent D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
2019-11-04 23:43:53.464 19692-19721/com.example.downloadwebcontent D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
2019-11-04 23:43:53.680 19692-19692/com.example.downloadwebcontent W/nloadwebconten: Accessing hidden method Landroid/view/View;computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2019-11-04 23:43:53.686 19692-19692/com.example.downloadwebcontent W/nloadwebconten: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2019-11-04 23:43:53.815 19692-19727/com.example.downloadwebcontent D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2019-11-04 23:43:53.855 19692-19727/com.example.downloadwebcontent W/System.err: java.net.SocketException: socket failed: EPERM (Operation not permitted)
2019-11-04 23:43:53.856 19692-19727/com.example.downloadwebcontent W/System.err: at java.net.Socket.createImpl(Socket.java:492)
2019-11-04 23:43:53.856 19692-19727/com.example.downloadwebcontent W/System.err: at java.net.Socket.getImpl(Socket.java:552)
2019-11-04 23:43:53.856 19692-19727/com.example.downloadwebcontent W/System.err: at java.net.Socket.setSoTimeout(Socket.java:1180)
2019-11-04 23:43:53.865 19692-19727/com.example.downloadwebcontent W/System.err: at com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:143)
2019-11-04 23:43:53.865 19692-19727/com.example.downloadwebcontent W/System.err: at com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:116)
2019-11-04 23:43:53.865 19692-19727/com.example.downloadwebcontent W/System.err: at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:186)
2019-11-04 23:43:53.866 19692-19727/com.example.downloadwebcontent W/System.err: at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:128)
2019-11-04 23:43:53.866 19692-19727/com.example.downloadwebcontent W/System.err: at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:97)
2019-11-04 23:43:53.866 19692-19727/com.example.downloadwebcontent W/System.err: at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:289)
2019-11-04 23:43:53.866 19692-19727/com.example.downloadwebcontent W/System.err: at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:232)
2019-11-04 23:43:53.866 19692-19727/com.example.downloadwebcontent W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:465)
2019-11-04 23:43:53.866 19692-19727/com.example.downloadwebcontent W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:411)
2019-11-04 23:43:53.866 19692-19727/com.example.downloadwebcontent W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:248)
2019-11-04 23:43:53.866 19692-19727/com.example.downloadwebcontent W/System.err: at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:211)
2019-11-04 23:43:53.866 19692-19727/com.example.downloadwebcontent W/System.err: at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:30)
2019-11-04 23:43:53.867 19692-19727/com.example.downloadwebcontent W/System.err: at com.example.downloadwebcontent.MainActivity$DownloadTask.doInBackground(MainActivity.java:28)
2019-11-04 23:43:53.867 19692-19727/com.example.downloadwebcontent W/System.err: at com.example.downloadwebcontent.MainActivity$DownloadTask.doInBackground(MainActivity.java:18)
2019-11-04 23:43:53.867 19692-19727/com.example.downloadwebcontent W/System.err: at android.os.AsyncTask$3.call(AsyncTask.java:378)
2019-11-04 23:43:53.867 19692-19727/com.example.downloadwebcontent W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2019-11-04 23:43:53.871 19692-19727/com.example.downloadwebcontent W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:289)
2019-11-04 23:43:53.871 19692-19727/com.example.downloadwebcontent W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
2019-11-04 23:43:53.871 19692-19727/com.example.downloadwebcontent W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
2019-11-04 23:43:53.874 19692-19727/com.example.downloadwebcontent W/System.err: at java.lang.Thread.run(Thread.java:919)
2019-11-04 23:43:53.874 19692-19692/com.example.downloadwebcontent I/info: Failed
2019-11-04 23:43:54.118 19692-19717/com.example.downloadwebcontent D/HostConnection: HostConnection::get() New Host Connection established 0xd4b81f00, tid 19717
2019-11-04 23:43:54.122 19692-19717/com.example.downloadwebcontent D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0
2019-11-04 23:43:54.145 19692-19717/com.example.downloadwebcontent W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2019-11-04 23:43:54.151 19692-19717/com.example.downloadwebcontent D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0
2019-11-04 23:43:54.151 19692-19717/com.example.downloadwebcontent D/EGL_emulation: eglCreateContext: 0xe0204ec0: maj 3 min 0 rcv 3
2019-11-04 23:43:54.153 19692-19717/com.example.downloadwebcontent D/EGL_emulation: eglMakeCurrent: 0xe0204ec0: ver 3 0 (tinfo 0xe0234b90)
2019-11-04 23:43:54.200 19692-19717/com.example.downloadwebcontent W/Gralloc3: mapper 3.x is not supported
2019-11-04 23:43:54.204 19692-19717/com.example.downloadwebcontent D/HostConnection: createUnique: call
2019-11-04 23:43:54.205 19692-19717/com.example.downloadwebcontent D/HostConnection: HostConnection::get() New Host Connection established 0xd4b83760, tid 19717
2019-11-04 23:43:54.206 19692-19717/com.example.downloadwebcontent D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0
2019-11-04 23:43:54.206 19692-19717/com.example.downloadwebcontent D/eglCodecCommon: allocate: Ask for block of size 0x1000
2019-11-04 23:43:54.207 19692-19717/com.example.downloadwebcontent D/eglCodecCommon: allocate: ioctl allocate returned offset 0x3ff803000 size 0x2000
2019-11-04 23:43:54.234 19692-19717/com.example.downloadwebcontent D/EGL_emulation: eglMakeCurrent: 0xe0204ec0: ver 3 0 (tinfo 0xe0234b90)
2019-11-04 23:43:54.243 19692-19717/com.example.downloadwebcontent D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 1 0
答案 0 :(得分:0)
在您的AndroidManifest.xml的应用程序标签中添加以下标签
android:usesCleartextTraffic="true"
答案 1 :(得分:0)
我认为这是android studio的错误。 今天,我只是将android studio版本从3.5.1更新为3.5.2,问题就解决了。