I want to write ByteArray data which is coming from Retrofit API(ResponseBody as return type from API) into Excel file and store into Internal Memory of android SD Card
try {
var path = mContext?. getExternalFilesDir(Environment.DIRECTORY_PICTURES)
val stream = FileOutputStream(path.toString()+"/ExcelTest.xls")
stream.write(it.data?.bytes())//it.data->retrofit ResponseBody that am convert to ByteArray
stream.flush()
stream.close()
//To open the Excel file
val intent = Intent(Intent.ACTION_VIEW).apply {
setDataAndType(Uri.fromFile(path), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
}
mContext?.startActivity(intent)
} catch (e: FileNotFoundException) {
}
Below is my Suspend Method:
@GET("URL")
@Streaming
suspend fun getDownloadFile():ResponseBody
New contributor
Ajay gadadasu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.