Kivy Android pyjnius - jnius.jnius.JavaException: JVM 异常发生:文件通过 ClipData.Item.getUri()

问题描述

我在 Kivy 中构建了一个 Android 应用程序,它可以合并和共享 pdf 文件。该应用程序运行良好,但当我尝试共享 pdf 时出现以下错误

jnius.jnius.JavaException: JVM exception occurred: file exposed beyond app through ClipData.Item.getUri()

我能够成功共享文本,但是当我尝试共享 pdf 文件(二进制对象)时,它失败了。有人可以帮忙吗?以下是我的代码

from jnius import autoclass,cast

def open_pdf(self):
        PythonActivity = autoclass('org.kivy.android.PythonActivity')
        Intent = autoclass('android.content.Intent')
        String = autoclass('java.lang.String')
        Uri = autoclass('android.net.Uri')
        File = autoclass('java.io.File')
        shareIntent = Intent(Intent.ACTION_SEND)
        shareIntent.setType('application/pdf')
        shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
        PdfFile = File(self.final_pdf_path)
        uri = Uri.fromFile(PdfFile)
        shareIntent.putExtra(Intent.EXTRA_STREAM,uri)
        #parcelable = cast('android.os.Parcelable',uri)
        #shareIntent.putExtra(Intent.EXTRA_STREAM,parcelable)
        chooser = Intent.createChooser(shareIntent,String('Share...'))
        currentActivity = cast('android.app.Activity',PythonActivity.mActivity)
        #currentActivity.startActivity(shareIntent)
        currentActivity.startActivity(chooser)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)