【问题标题】:Android external PDF rendering closes immediatelyAndroid 外部 PDF 渲染立即关闭
【发布时间】:2023-03-21 07:04:01
【问题描述】:

我正在尝试从我的 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 不起作用。

【问题讨论】:

标签: android kotlin


【解决方案1】:

这在某些使用默认 Drive PDF Viewer 的手机上不起作用。尝试使用应用选择器使用替代 PDF 查看器。

【讨论】:

    猜你喜欢
    • 2017-06-06
    • 1970-01-01
    • 1970-01-01
    • 2020-04-20
    • 1970-01-01
    • 2011-10-28
    • 1970-01-01
    • 1970-01-01
    • 2011-09-29
    相关资源
    最近更新 更多