So after 3 days of wanting to jump off a cliff. I found the answer. Of course it was a few minutes after asking the question here (first question ever so be kind.). The only Issue is you need a SSL cert for HTTPS on the server retrieving the file. My server is http but i can get a cert in there and fix that. to Test i threw up a github repository and linked to the raw text file. Here is my solution if this saves you 3 days pour one out for me.
Thread {
try {
val url = URL("https://raw.githubusercontent.com/USERNAME/NeedHTTPSdontWanaSSL/main/info.txt")
val uc: HttpsURLConnection = url.openConnection() as HttpsURLConnection
val br = BufferedReader(InputStreamReader(uc.getInputStream()))
var line: String?
val lin2 = StringBuilder()
while (br.readLine().also { line = it } != null) {
lin2.append(line)
}
Log.d("The Text", "$lin2")
} catch (e: IOException) {
Log.d("texts", "onClick: " + e.getLocalizedMessage())
e.printStackTrace()
}
}.start()
Credit: answered Aug 12, 2018 at 9:29 Aishik kirtaniya Android - How can I read a text file from a url?
Answer from GraduatedImposterSynd on Stack OverflowSo after 3 days of wanting to jump off a cliff. I found the answer. Of course it was a few minutes after asking the question here (first question ever so be kind.). The only Issue is you need a SSL cert for HTTPS on the server retrieving the file. My server is http but i can get a cert in there and fix that. to Test i threw up a github repository and linked to the raw text file. Here is my solution if this saves you 3 days pour one out for me.
Thread {
try {
val url = URL("https://raw.githubusercontent.com/USERNAME/NeedHTTPSdontWanaSSL/main/info.txt")
val uc: HttpsURLConnection = url.openConnection() as HttpsURLConnection
val br = BufferedReader(InputStreamReader(uc.getInputStream()))
var line: String?
val lin2 = StringBuilder()
while (br.readLine().also { line = it } != null) {
lin2.append(line)
}
Log.d("The Text", "$lin2")
} catch (e: IOException) {
Log.d("texts", "onClick: " + e.getLocalizedMessage())
e.printStackTrace()
}
}.start()
Credit: answered Aug 12, 2018 at 9:29 Aishik kirtaniya Android - How can I read a text file from a url?
How about this?
import java.net.URL
val s = "https://www.someplace.com/dir/file.txt"
val text = URL(s).openStream().readAllBytes().decodeToString()
Wrap it in some exception handling if you want. So long as you don't keep references to the intermediate stream, it'll immediately be eligible for garbage collection. The stream will be closed when it's garbage collected, thus I don't bother with adding a call to explicitly close it.
Help enabling downloads through webview (Kotlin)
Can I convert url to File?
Download file from url in android using retrofit
How to Extract the File Name from URI in Android 14?
Videos
Hi everyone, i'm making tg bot using JAICF framework. I want bot to send video, but this command requires File class (prt sc down below), but I have only url (String) from youtube. Any ideas how can I convert this?