相关疑难解决方法(0)

kivy android 分享图片

我想创建共享按钮,该按钮将使用 android ACTION_SEND 意图来共享图像。这是我的代码:

from kivy.setupconfig import USE_SDL2


def share(path):
    if platform == 'android':
        from jnius import cast
        from jnius import autoclass
        if USE_SDL2:
            PythonActivity = autoclass('org.kivy.android.PythonActivity')
        else:
            PythonActivity = autoclass('org.renpy.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('"image/*"')
        imageFile = File(path)
        uri = Uri.fromFile(imageFile)
        shareIntent.putExtra(Intent.EXTRA_STREAM, uri)

        currentActivity = cast('android.app.Activity', PythonActivity.mActivity)
        currentActivity.startActivity(shareIntent)
Run Code Online (Sandbox Code Playgroud)

但它不起作用)它jnius.jnius.JavaException: Invalid instance of u'android/net/Uri' passed for a u'java/lang/String'在这一行中引发了这个错误shareIntent.putExtra(Intent.EXTRA_STREAM, uri)。我怎样才能解决这个问题?

python android kivy pyjnius

7
推荐指数
1
解决办法
1812
查看次数

标签 统计

android ×1

kivy ×1

pyjnius ×1

python ×1