kivy android分享图片

kivy android分享图片,第1张

概述我想创建将使用 Android ACTION_SEND意图共享图像的共享按钮.这是我的代码: from kivy.setupconfig import USE_SDL2def share(path): if platform == 'android': from jnius import cast from jnius import autoclass 我想创建将使用 Android ACTION_SEND意图共享图像的共享按钮.这是我的代码:

from kivy.setupconfig import USE_SDL2def 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)

但它不起作用)它抛出此错误jnius.jnius.JavaException:u’androID / net / Uri’的无效实例在此行中传递给u’java / lang / String’shareIntent.putExtra(Intent.EXTRA_STREAM,URI).我怎样才能解决这个问题?

解决方法 我找到了解决方案您必须将uri转换为parcelable,然后将其传递给intent:

parcelable = cast('androID.os.Parcelable',uri)shareIntent.putExtra(Intent.EXTRA_STREAM,parcelable)
总结

以上是内存溢出为你收集整理的kivy android分享图片全部内容,希望文章能够帮你解决kivy android分享图片所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1128121.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存