Search code examples
androidkotlinandroid-volley

Cannot connect to http sites with Volley (Andoid, Kotlin) (https works fine)


This is the first time that I am dipping my toes into andoroid development. For this I decided to make a little project to get into it.

My settup: I want to control an led strip with a Raspberry Pi Pico W with my own android app. The Pico hosts a Webpage that I can access with its local IP adress. To change the LED's I can go to, for eg:192.168.0.201/setrgb/255/000/000 this would make the LED strip Red. (This works fine in a browser)

Using this article I set up a simple string request with volley. Using the example "https://www.google.com" works just fine and I get the html code of google.com as a string. However whenever I try to access my Pico it prints: "that didn't work" (see the code below). It also doesn't work with "http://www.columbia.edu/~fdc/sample.html" although I don't really know why.

Could it have something to do with the fact that google uses https and the other use http?

println("start")
        val queue = Volley.newRequestQueue(this)
        val url = "http://192.168.0.201/setrgb/000/000/000"

        val stringRequest = StringRequest(Request.Method.GET, url,
            { response ->
                println((url))
                println("response:")
                println(response)
                println("end of response")
            },
            { println("that didn't work")
            println(url)})

// Add the request to the RequestQueue.
        queue.add(stringRequest)

This is the output:

System.out                           I  start
Volley                               V  [61] CacheDispatcher.run: start new dispatcher
System.out                           I  damn
Volley                               D  [61] WaitingRequestManager.maybeAddToWaitingRequests: new request, sending to network http://192.168.0.201/setrgb/000/000/000
HostConnection                       D  createUnique: call
HostConnection                       D  HostConnection::get() New Host Connection established 0x7cfd607d6010, tid 32234
HostConnection                       D  HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 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_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_vulkan_queue_submit_with_commands ANDROID_EMU_sync_buffer_data ANDROID_EMU_read_color_buffer_dma ANDROID_EMU_hwc_multi_configs GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_
OpenGLRenderer                       W  Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
OpenGLRenderer                       W  Failed to initialize 101010-2 format, error = EGL_SUCCESS
EGL_emulation                        D  eglCreateContext: 0x7cfd607d8290: maj 2 min 0 rcv 2
EGL_emulation                        D  eglMakeCurrent: 0x7cfd607d8290: ver 2 0 (tinfo 0x7cff77380080) (first time)
Gralloc4                             I  mapper 4.x is not supported
HostConnection                       D  createUnique: call
HostConnection                       D  HostConnection::get() New Host Connection established 0x7cfd607d7b10, tid 32234
goldfish-address-space               D  allocate: Ask for block of size 0x100
goldfish-address-space               D  allocate: ioctl allocate returned offset 0x3ebffe000 size 0x2000
Gralloc4                             W  allocator 4.x is not supported
HostConnection                       D  HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 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_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_vulkan_queue_submit_with_commands ANDROID_EMU_sync_buffer_data ANDROID_EMU_read_color_buffer_dma ANDROID_EMU_hwc_multi_configs GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_
Parcel                               W  Expecting binder but got null!
System.out                           I  that didn't work
System.out                           I  http://192.168.0.201/setrgb/000/000/000
Volley                               D  [2] MarkerLog.finish: (298  ms) [ ] http://192.168.0.201/setrgb/000/000/000 0x85adfa16 NORMAL 1
Volley                               D  [2] MarkerLog.finish: (+0   ) [ 2] add-to-queue
Volley                               D  [2] MarkerLog.finish: (+1   ) [61] cache-queue-take
Volley                               D  [2] MarkerLog.finish: (+0   ) [61] cache-miss
Volley                               D  [2] MarkerLog.finish: (+0   ) [62] network-queue-take
Volley                               D  [2] MarkerLog.finish: (+7   ) [62] post-error
Volley                               D  [2] MarkerLog.finish: (+290 ) [ 2] done

There seems to be some sort of "post-error", but I really don't know why and I can't really find anything though google.

The Following is the output if I use a working website like google.com:

[2] MarkerLog.finish: (+0   ) [ 2] add-to-queue
[2] MarkerLog.finish: (+2   ) [76] cache-queue-take
[2] MarkerLog.finish: (+0   ) [76] cache-miss
[2] MarkerLog.finish: (+1   ) [77] network-queue-take
[2] MarkerLog.finish: (+340 ) [77] network-http-complete
[2] MarkerLog.finish: (+5   ) [77] network-parse-complete
[2] MarkerLog.finish: (+3   ) [77] network-cache-written
[2] MarkerLog.finish: (+0   ) [77] post-response
[2] MarkerLog.finish: (+338 ) [ 2] done

Does anyone know how to fix this or do you have other ideas how to achive what I want?


Solution

  • I ended up figuring it out myself. The problem had to do with the fact that the website I tried to access used http instead of https:

    To give permission to acces http websites I added folowing line to the manifest.xml file:

    android:usesCleartextTraffic="true"
    

    It goes after <application.