Android外部PDF渲染立即关闭
我正在尝试从Android应用程序外部呈现PDF。 我的代码如下所示Android外部PDF渲染立即关闭,android,kotlin,Android,Kotlin,我正在尝试从Android应用程序外部呈现PDF。 我的代码如下所示 val file = File(<path-to-pdf>) val target = Intent(Intent.ACTION_VIEW) target.setDataAndType(Uri.fromFile(file), "application/pdf") target.flags = Intent.FLAG_ACTIVITY_NO_HISTORY val intent = Intent.createChoo
val file = File(<path-to-pdf>)
val target = Intent(Intent.ACTION_VIEW)
target.setDataAndType(Uri.fromFile(file), "application/pdf")
target.flags = Intent.FLAG_ACTIVITY_NO_HISTORY
val intent = Intent.createChooser(target, "Open With")
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
try {
context.startActivity(intent)
} catch (e: ActivityNotFoundException) {
Log.e(e.message)
}
val file=file()
val target=Intent(Intent.ACTION_视图)
target.setDataAndType(Uri.fromFile(文件),“application/pdf”)
target.flags=Intent.FLAG\u活动\u否\u历史记录
val intent=intent.createChooser(目标“打开”)
intent.flags=intent.FLAG\u活动\u新任务
试一试{
上下文。起始触觉(意图)
}捕获(e:ActivityNotFoundException){
Log.e(e.message)
}
无论何时在某些设备上运行(到目前为止在像素2上观察到),外部读卡器都会启动并立即关闭。
建议的解决方案不起作用。这在使用默认的
驱动器PDF查看器的某些手机上不起作用。尝试使用应用程序选择器使用其他PDF查看器。其他应用程序无法访问应用程序中的文件:URI。安卓7.0增加了这一限制。例如,考虑一个文件提供者。不过,它在某些手机上也能正常工作。这类问题是否可能只发生在某些设备上?