0

I'm trying to Log.d the title of wikipedia.org. connect(URL).get() keeps returning null. I'm getting an "Unknown bits set in runtime_flags: 0x8000" error, but the code is still running otherwise. The app doesn't crash and logs that doc is null. Here's my class that extends AsyncTask:

private class Content extends AsyncTask<Void, Void, Void>
    {
    String title;
    Document doc;
    String url = "http://www.wikipedia.org";

    @Override
    protected void onPreExecute()
    {

    }

    @Override
    protected Void doInBackground(Void... voids)
    {
        try
        {
            doc  = Jsoup.connect(url).get();
            title = doc.title();

        }
        catch(IOException ex)
        {
            ex.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(Void aVoid)
    {
        if(doc != null)
        {
            Log.d("title", "doc found");
            Log.d("title", title);
        }
        else
        {
            Log.d("title", "nada");
        }
    }

}

Edit: Here's what I got in Logcat

2019-11-20 09:00:06.620 14197-14197/? I/e.findbestpric: Not late-enabling -Xcheck:jni (already on)
2019-11-20 09:00:06.681 14197-14197/? E/e.findbestpric: Unknown bits set in runtime_flags: 0x8000
2019-11-20 09:00:06.930 14197-14197/? W/e.findbestpric: Unexpected CPU variant for X86 using defaults: x86
2019-11-20 09:00:07.115 14197-14243/? D/libEGL: Emulator has host GPU support, qemu.gles is set to 1.
2019-11-20 09:00:07.126 14197-14243/? W/libc: Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied)
2019-11-20 09:00:07.104 14197-14197/? W/RenderThread: type=1400 audit(0.0:117): avc: denied { write } for name="property_service" dev="tmpfs" ino=8237 scontext=u:r:untrusted_app:s0:c136,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0
2019-11-20 09:00:07.136 14197-14243/? D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
2019-11-20 09:00:07.137 14197-14243/? D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
2019-11-20 09:00:07.139 14197-14243/? D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
2019-11-20 09:00:07.251 14197-14197/? W/e.findbestpric: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2019-11-20 09:00:07.252 14197-14197/? W/e.findbestpric: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2019-11-20 09:00:07.560 14197-14245/? D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2019-11-20 09:00:07.563 14197-14245/? W/System.err: java.io.IOException: Cleartext HTTP traffic to www.wikipedia.org not permitted
2019-11-20 09:00:07.564 14197-14245/? W/System.err:     at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:124)
2019-11-20 09:00:07.564 14197-14245/? W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:462)
2019-11-20 09:00:07.564 14197-14245/? W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:131)
2019-11-20 09:00:07.564 14197-14245/? W/System.err:     at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:730)
2019-11-20 09:00:07.564 14197-14245/? W/System.err:     at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:705)
2019-11-20 09:00:07.564 14197-14245/? W/System.err:     at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:295)
2019-11-20 09:00:07.564 14197-14245/? W/System.err:     at org.jsoup.helper.HttpConnection.get(HttpConnection.java:284)
2019-11-20 09:00:07.564 14197-14245/? W/System.err:     at com.example.findbestprice.MainActivity$Content.doInBackground(MainActivity.java:105)
2019-11-20 09:00:07.564 14197-14245/? W/System.err:     at com.example.findbestprice.MainActivity$Content.doInBackground(MainActivity.java:88)
2019-11-20 09:00:07.564 14197-14245/? W/System.err:     at android.os.AsyncTask$3.call(AsyncTask.java:378)
2019-11-20 09:00:07.564 14197-14245/? W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2019-11-20 09:00:07.564 14197-14245/? W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:289)
2019-11-20 09:00:07.564 14197-14245/? W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
2019-11-20 09:00:07.564 14197-14245/? W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
2019-11-20 09:00:07.564 14197-14245/? W/System.err:     at java.lang.Thread.run(Thread.java:919)
2019-11-20 09:00:07.586 14197-14241/? D/HostConnection: HostConnection::get() New Host Connection established 0xd20d3e60, tid 14241
2019-11-20 09:00:07.589 14197-14241/? D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_2 
2019-11-20 09:00:07.591 14197-14241/? W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2019-11-20 09:00:07.592 14197-14241/? D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0
2019-11-20 09:00:07.592 14197-14241/? D/EGL_emulation: eglCreateContext: 0xdd743c80: maj 2 min 0 rcv 2
2019-11-20 09:00:07.626 14197-14241/? D/EGL_emulation: eglMakeCurrent: 0xdd743c80: ver 2 0 (tinfo 0xd212b280)
2019-11-20 09:00:07.661 14197-14241/? W/Gralloc3: mapper 3.x is not supported
2019-11-20 09:00:07.663 14197-14241/? D/HostConnection: createUnique: call
2019-11-20 09:00:07.670 14197-14241/? D/HostConnection: HostConnection::get() New Host Connection established 0xd20d58f0, tid 14241
2019-11-20 09:00:07.671 14197-14241/? D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_2 
2019-11-20 09:00:07.671 14197-14241/? D/eglCodecCommon: allocate: Ask for block of size 0x1000
2019-11-20 09:00:07.673 14197-14241/? D/eglCodecCommon: allocate: ioctl allocate returned offset 0x3ff803000 size 0x2000
2019-11-20 09:00:07.717 14197-14241/? D/EGL_emulation: eglMakeCurrent: 0xdd743c80: ver 2 0 (tinfo 0xd212b280)
2019-11-20 09:00:07.722 14197-14241/? D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 1 0
2019-11-20 09:00:07.818 14197-14197/? D/title: nada

1 Answers1

0

Your error is

java.io.IOException: Cleartext HTTP traffic to www.wikipedia.org not permitted

Android removed support for cleartext traffic by default, so to enable it you can try adding support for cleartext traffic in the android manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <uses-permission android:name="android.permission.INTERNET"/>
    <application
        ...
        android:usesCleartextTraffic="true"
        ...>
        ...
    </application>
</manifest>

For more information (if above doesn't work) this should solve your problem: Android 8: Cleartext HTTP traffic not permitted

Joe
  • 1,316
  • 9
  • 17
  • That helped a bit, but now I'm getting a "java.net.SocketException: socket failed: EPERM (Operation not permitted)" error. I looked into it a bit and added permissions for ACCESS_NETWORK_STATE and ACCESS_WIFI_STATE, but I'm still getting the same SocketException error. – Daniel Archuleta Nov 20 '19 at 17:09
  • 1
    Ok, I just needed to reinstall the app on the emulator. It's working now! Thanks – Daniel Archuleta Nov 20 '19 at 22:07
  • Not a problem brother – Joe Nov 21 '19 at 14:22