My android app create an csv file and share it immediately as the below code. The app start properly but there is no file attached when i select anyone of the application to share it. please kindly help to solve this issue.
class MainActivity : AppCompatActivity() {
private val CSV_HEADER = "id,name,address,age"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val qponFile = File.createTempFile("qpon", "csv")
var fileWriter: FileWriter? = null
try {
fileWriter = FileWriter("qpon.csv")
fileWriter.append(CSV_HEADER)
fileWriter.append('\n')
fileWriter.append("aaaaa")
fileWriter.append(',')
fileWriter.append("bbbbb")
fileWriter.append(',')
fileWriter.append("cccccc")
fileWriter.append(',')
fileWriter.append("dddddd")
fileWriter.append('\n')
println("Write CSV successfully!")
} catch (e: Exception) {
println("Writing CSV error!")
e.printStackTrace()
}
val sendIntent = Intent()
sendIntent.action = Intent.ACTION_SEND
sendIntent.putExtra(Intent.EXTRA_STREAM, qponFile)
sendIntent.type = "text/csv"
startActivity(Intent.createChooser(sendIntent, "SHARE"))
}
}