我正在尝试从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:不延迟启用-Xcheck:jni(已启用)
2019-11-04 23:43:52.870 19692-19692 /? E / nloadwebconten:在runtime_flags中设置的未知位:0x8000
2019-11-04 23:43:52.872 19692-19692 /? W / nloadwebconten:使用默认值的x86的CPU意外变体:x86
2019-11-04 23:43:53.355 19692-19721 / com.example.downloadwebcontent D / libEGL:仿真器具有主机GPU支持,qemu.gles设置为1。
2019-11-04 23:43:53.340 19692-19692 / com.example.downloadwebcontent W / RenderThread:类型= 1400审核(0.0:147):AVC:拒绝{写入}名称=“ 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允许= 0
2019-11-04 23:43:53.356 19692-19721 / com.example.downloadwebcontent W / libc:无法将属性“ qemu.gles”设置为“ 1”:连接失败; errno = 13(权限被拒绝)
2019-11-04 23:43:53.386 19692-19721 / com.example.downloadwebcontent D / libEGL:已加载/vendor/lib/egl/libEGL_emulation.so
2019-11-04 23:43:53.406 19692-19721 / com.example.downloadwebcontent D / libEGL:已加载/vendor/lib/egl/libGLESv1_CM_emulation.so
2019-11-04 23:43:53.464 19692-19721 / com.example.downloadwebcontent D / libEGL:已加载/vendor/lib/egl/libGLESv2_emulation.so
2019-11-04 23:43:53.680 19692-19692 / com.example.downloadwebcontent W / nloadwebconten:访问隐藏的方法Landroid / view / View; computeFitSystemWindows(Landroid / graphics / Rect; Landroid / graphics / Rect;)Z (灰名单,反思,允许)
2019-11-04 23:43:53.686 19692-19692 / com.example.downloadwebcontent W / nloadwebconten:访问隐藏的方法Landroid / view / ViewGroup;-> makeOptionalFitsSystemWindows()V(灰色列表,反射,允许)
2019-11-04 23:43:53.815 19692-19727 / com.example.downloadwebcontent D / NetworkSecurityConfig:未指定网络安全配置,使用平台默认值
2019-11-04 23:43:53.855 19692-19727 / com.example.downloadwebcontent W / System.err:java.net.SocketException:套接字失败:EPERM(不允许操作)
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:在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:失败
2019-11-04 23:43:54.118 19692-19717 / com.example.downloadwebcontent D / HostConnection:HostConnection :: get()建立新的主机连接0xd4b81f00,tid 19717
2019年11月4日23:43:54.122 19692-19717 / com.example.downloadwebcontent D / HostConnection:HostComposition分机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:无法使用EGL_SWAP_BEHAVIOR_PRESERVED选择配置,请重试而无需...
2019-11-04 23:43:54.151 19692-19717 / com.example.downloadwebcontent D / eglCodecCommon:setVertexArrayObject:将vao设置为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]
2019-11-04 23:43:54.204 19692-19717 / com.example.downloadwebcontent D / HostConnection:createUnique:调用
2019-11-04 23:43:54.205 19692-19717 / com.example.downloadwebcontent D / HostConnection:HostConnection :: get()建立新的主机连接0xd4b83760,tid 19717
2019年11月4日23:43:54.206 19692-19717 / com.example.downloadwebcontent D / HostConnection:HostComposition分机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:分配:要求块大小为0x10002019-11-04 23:43:54.207 19692-19717 / com.example.downloadwebcontent D / eglCodecCommon:分配:ioctl分配返回的偏移量0x3ff803000大小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:将vao设置为0(0)1 0
在AndroidManifest.xml的应用程序标签中添加以下标签
android:usesCleartextTraffic="true"