I need to read data from a file from a github txt file, I tried a lot but was unsuccessful. I had included
<uses-permission android:name=android.permission.INTERNET/>
<uses-permission android:name=android.permission.WRITE_EXTERNAL_STORAGE/>
in my manifest file.
I used this link for receiving data: https://raw.githubusercontent.com/Tanay360/Sample/main/hello.txt
This was my onCreate method :
override fun onCreate(savedInstanceState : Bundle?){
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val thread : Thread = Thread{
read()
}
val button : Button = findViewById(R.id.b1)
b1.setOnClickListener{
thread.start()
}}
This is my read method :
fun read(){
val url = URL("https://raw.githubusercontent.com/Tanay360/Sample/main/hello.txt")
val sc = Scanner(url.openStream())
var str = ""
while(sc.hasNextLine()){
str+=sc.nextLine()+"\n"
}
Log.d(TAG, "read : $str")
val tv : TextView = findViewById(R.id.normalTextView)
tv.text = str}
Whenever, I run the app, no compile-time errors are thrown, and on clicking the button nothing happens!
Please help me...
Thank you!