0

I am trying to execute a link so that I can control an ESP32 using Kotlin in Android Studio, but it is unable to execute it the same way a WebView can (I use the WebView to get a video feed, and it is able to transfer the video). The below is my code

Activity

val url = URL(ipcomm2)
val con: HttpURLConnection = url.openConnection() as HttpURLConnection
con.requestMethod = "POST"

WebView

setContentView(webview)
webview.loadUrl(IPfeed)

Can someone explain why this is the case? Thanks.

Cheng Poh
  • 9
  • 3

1 Answers1

0

You need to call getInputStream and read it out.

See https://developer.android.com/reference/java/net/HttpURLConnection

Madushan
  • 5,183
  • 25
  • 57
  • I have done as suggested but I don't know why readStream is unavailable after my getInputStream? It shows up highlighted in red – Cheng Poh Feb 12 '21 at 11:48
  • `readStream` in the sample is a pseudo method you have to implement. Checkout this question on how to read a stream in Java. Pasting the code in to Android Studio should automatically convert it to Kotlin. https://stackoverflow.com/questions/309424/how-do-i-read-convert-an-inputstream-into-a-string-in-java – Madushan Feb 13 '21 at 05:06