looking for some solutions? You are welcome.

SOLVED: Open .csv file programmatically in android using kotlin

Arnolfo Teope:

I want to open a .csv file when clicking on a button, but it does not work.

Here is my code:

btncsv.setOnClickListener {
    val tempFile = File(Environment.getExternalStorageDirectory().absolutePath+"/HydroWatchFolder/hydrowatchData.csv")
    val intent = Intent()
    intent.action = android.content.Intent.ACTION_VIEW
    val mime = MimeTypeMap.getSingleton()
    val ext = tempFile.name.substring(tempFile.name.indexOf(".") + 1).toLowerCase()
    val type = mime.getMimeTypeFromExtension(ext)
    intent.setDataAndType(Uri.fromFile(tempFile), type)
    Toast.makeText(this,"$intent", Toast.LENGTH_LONG).show()
    startActivity(intent)
}



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent