小编kit*_*041的帖子

在Android上发送带有Kivy应用附件的电子邮件,最好是打开电子邮件客户端

我尝试了几种方法在Android上的Kivy应用程序中使用Python发送电子邮件.我最接近的是使用Plyer的电子邮件功能(https://plyer.readthedocs.org/en/latest/#plyer.facades.Email),但它似乎不支持附件.

我希望我的应用程序做的是打开用户的电子邮件客户端并填充收件人,主题,正文和附件字段.附件将是我的应用程序生成的.csv文件.

有没有人有关于如何做到这一点的建议?如何修改此代码以包含附件?

from jnius import autoclass, cast
from plyer.facades import Email
from plyer.platforms.android import activity

Intent = autoclass('android.content.Intent')
AndroidString = autoclass('java.lang.String')


class AndroidEmail(Email):
    def _send(self, **kwargs):
    intent = Intent(Intent.ACTION_SEND)
    intent.setType('text/plain')

    recipient = kwargs.get('recipient')
    subject = kwargs.get('subject')
    text = kwargs.get('text')
    create_chooser = kwargs.get('create_chooser')

    if recipient:
        intent.putExtra(Intent.EXTRA_EMAIL, [recipient])
    if subject:
        android_subject = cast('java.lang.CharSequence',
                               AndroidString(subject))
        intent.putExtra(Intent.EXTRA_SUBJECT, android_subject)
    if text:
        android_text = cast('java.lang.CharSequence',
                            AndroidString(text))
        intent.putExtra(Intent.EXTRA_TEXT, android_text)

    if create_chooser:
        chooser_title = cast('java.lang.CharSequence',
                             AndroidString('Send message with:'))
        activity.startActivity(Intent.createChooser(intent,
                                                    chooser_title))
    else:
        activity.startActivity(intent)


def instance():
    return …
Run Code Online (Sandbox Code Playgroud)

python android kivy pyjnius

5
推荐指数
1
解决办法
1328
查看次数

标签 统计

android ×1

kivy ×1

pyjnius ×1

python ×1