How to load .rtf files in webview?

Viewed 274

enter image description hereI want to load rtf files with webview using raw folder. Below is my code;

 val urlWebView = findViewById<WebView>(R.id.webview)
 readTextFromResource(R.raw.lettemp_369)?.let { urlWebView.loadData(it, "text/rtf", "utf-8") };

Below is function;

private fun readTextFromResource(resourceID: Int): String? {
val raw: InputStream = resources.openRawResource(resourceID)
val stream = ByteArrayOutputStream()
var i: Int
 try {
i = raw.read()
while (i != -1) {
    stream.write(i)
    i = raw.read()
}
raw.close()
} catch (e: IOException) {
e.printStackTrace()
}
return stream.toString()
}
0 Answers
Related