프로그래밍/Android
Android Kotlin openPDF
프리월드
2023. 5. 12. 17:48
fun openPDF(path: String?) {
if (!TextUtils.isEmpty(path)) {
val u_path = Uri.parse(path)
val intent = Intent(Intent.ACTION_VIEW)
intent.setDataAndType(u_path, "application/pdf")
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
try {
mContext.startActivity(intent)
} catch (e: ActivityNotFoundException) {
Toast.makeText(mContext, "PDF 파일을 보기 위한 뷰어 앱이 없습니다.", Toast.LENGTH_SHORT).show()
}
} else {
Toast.makeText(mContext, "PDF 파일이 없습니다.", Toast.LENGTH_SHORT).show()
}
}