我正在尝试从我的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.createChooser(target,"Open With")
intent.flags = Intent.flaG_actIVITY_NEW_TASK
try {
context.startactivity(intent)
} catch (e: activityNotFoundException) {
Log.e(e.message)
}
每当在某些设备上运行时(到目前为止在Pixel 2上观察到),外部读取器都会启动并立即关闭。 解决方案建议here不起作用。