0

I'm trying to download web content from my android application. But whenever I run, I have the problem below. I'm using android studio 3.5.1 on Mac.

Here are some code..

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";
            }
        }

The following are the error code:

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
Jernej K
  • 1,602
  • 2
  • 25
  • 38
  • Can you share the whole stacktrace. It is hard to see what is wrong. And please keep the same line endings, because it is hard to follow what is the actual issue. But it seems like it is an issue with permissions - `Permission denied` – Jernej K Nov 04 '19 at 17:50
  • yeah I think this is the main reason 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) – Louis Payne Nov 04 '19 at 17:54
  • I google a bit and found the following https://stackoverflow.com/questions/56266801/java-net-socketexception-socket-failed-eperm-operation-not-permitted. One of the problems one person had was missing network permission. For some uninstalling the app from the emulator was enough. – Jernej K Nov 04 '19 at 18:14
  • Basically I found two reasons for this to fail. One could be the missing network permission or it could be connected with the SDK install. – Jernej K Nov 04 '19 at 18:20

2 Answers2

0

Add the following tag in your application tag of AndroidManifest.xml

android:usesCleartextTraffic="true"
Swayangjit
  • 1,875
  • 2
  • 13
  • 22
0

I think it's the bug of android studio. Today I just update android studio version from 3.5.1 to 3.5.2 and the issue is gone.