I copied over some Java code and had it converted to Kotlin code. It compiles and runs, but it is unable to load online text and set that text to a textview. I get a lot of permission denied statements when checking on the status of the app while it is running.
package com.example.app
import android.os.Bundle
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import java.net.URLConnection
import java.net.URL
import java.util.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
var textBody: TextView = findViewById(R.id.textBody)
var content: String? = null
var connection: URLConnection? = null
try {
connection = URL("https://example.com").openConnection()
val scanner = Scanner(connection.getInputStream())
content = scanner.next()
scanner.close()
} catch (ex: Exception) {
ex.printStackTrace()
}
textBody.setText(content)
}
}