diff options
Diffstat (limited to 'external/plyer/platforms/android/email.py')
-rw-r--r-- | external/plyer/platforms/android/email.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/external/plyer/platforms/android/email.py b/external/plyer/platforms/android/email.py new file mode 100644 index 0000000..79923e4 --- /dev/null +++ b/external/plyer/platforms/android/email.py @@ -0,0 +1,40 @@ +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 AndroidEmail() |