简体   繁体   English

Android 外部 PDF 渲染立即关闭

[英]Android external PDF rendering closes immediately

I'm trying to externally render a PDF from my Android app.我正在尝试从我的 Android 应用程序外部渲染 PDF 。 My code looks like this我的代码看起来像这样

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)
}

Whenever this runs on certain devices (so far observed on Pixel 2), the external reader launches, and closes immediately.每当它在某些设备上运行时(到目前为止在 Pixel 2 上观察到),外部阅读器就会启动并立即关闭。 Solution suggested here did not work. 此处建议的解决方案不起作用。

This doesn't work on some phone using the default Drive PDF Viewer .这在某些使用默认Drive PDF Viewer的手机上不起作用。 Try using an alternative PDF viewer using the app picker.尝试使用应用选择器使用替代 PDF 查看器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM