| 1 | ''' |
| 2 | Module of Android API for plyer.email. |
| 3 | ''' |
| 4 | |
| 5 | from jnius import autoclass, cast |
| 6 | from plyer.facades import Email |
| 7 | from plyer.platforms.android import activity |
| 8 | |
| 9 | Intent = autoclass('android.content.Intent') |
| 10 | AndroidString = autoclass('java.lang.String') |
| 11 | |
| 12 | |
| 13 | class AndroidEmail(Email): |
| 14 | ''' |
| 15 | Implementation of Android email API. |
| 16 | ''' |
| 17 | |
| 18 | def _send(self, **kwargs): |
| 19 | intent = Intent(Intent.ACTION_SEND) |
| 20 | intent.setType('text/plain') |
| 21 | |
| 22 | recipient = kwargs.get('recipient') |
| 23 | subject = kwargs.get('subject') |
| 24 | text = kwargs.get('text') |
| 25 | create_chooser = kwargs.get('create_chooser') |
| 26 | |
| 27 | if recipient: |
| 28 | intent.putExtra(Intent.EXTRA_EMAIL, [recipient]) |
| 29 | if subject: |
| 30 | android_subject = cast( |
| 31 | 'java.lang.CharSequence', |
| 32 | AndroidString(subject) |
| 33 | ) |
| 34 | intent.putExtra(Intent.EXTRA_SUBJECT, android_subject) |
| 35 | if text: |
| 36 | android_text = cast( |
| 37 | 'java.lang.CharSequence', |
| 38 | AndroidString(text) |
| 39 | ) |
| 40 | intent.putExtra(Intent.EXTRA_TEXT, android_text) |
| 41 | |
| 42 | if create_chooser: |
| 43 | chooser_title = cast( |
| 44 | 'java.lang.CharSequence', |
| 45 | AndroidString('Send message with:') |
| 46 | ) |
| 47 | activity.startActivity( |
| 48 | Intent.createChooser(intent, chooser_title) |
| 49 | ) |
| 50 | else: |
| 51 | activity.startActivity(intent) |
| 52 | |
| 53 | |
| 54 | def instance(): |
| 55 | ''' |
| 56 | Instance for facade proxy. |
| 57 | ''' |
| 58 | return AndroidEmail() |