hi i want open excel files from my app in another office app i used this codes
val file = File(path)
val uri = FileProvider.getUriForFile(
activity!!.applicationContext,
BuildConfig.APPLICATION_ID.toString() + ".provider",
file
)
val intent = Intent(Intent.ACTION_VIEW)
//file is word
if (file.extension.contains("doc")){
intent.setDataAndType(uri, "application/word")
}else{
// file is excel
intent.setDataAndType(uri, "application/excel")
}
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
activity.startActivity(intent)
} catch (e: ActivityNotFoundException) {
snack(view,"برنامه ای برای نمایش فایل ورد/اکسل روی گوشی پیدا نشد، لطفا برنامه آفیس را روی گوشی خود نصب کنید")
}
but this code not work properly and it doesn't work on some phones and Android 10 So how do I make it work on all phones?