summaryrefslogtreecommitdiff
path: root/external/plyer/platforms/android/notification.py
diff options
context:
space:
mode:
Diffstat (limited to 'external/plyer/platforms/android/notification.py')
-rw-r--r--external/plyer/platforms/android/notification.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/external/plyer/platforms/android/notification.py b/external/plyer/platforms/android/notification.py
new file mode 100644
index 0000000..bfc3a25
--- /dev/null
+++ b/external/plyer/platforms/android/notification.py
@@ -0,0 +1,37 @@
+from jnius import autoclass
+from plyer.facades import Notification
+from plyer.platforms.android import activity, SDK_INT
+
+AndroidString = autoclass('java.lang.String')
+Context = autoclass('android.content.Context')
+NotificationBuilder = autoclass('android.app.Notification$Builder')
+Drawable = autoclass("{}.R$drawable".format(activity.getPackageName()))
+
+
+class AndroidNotification(Notification):
+ def _get_notification_service(self):
+ if not hasattr(self, '_ns'):
+ self._ns = activity.getSystemService(Context.NOTIFICATION_SERVICE)
+ return self._ns
+
+ def _notify(self, **kwargs):
+ icon = getattr(Drawable, kwargs.get('icon_android', 'icon'))
+ noti = NotificationBuilder(activity)
+ noti.setContentTitle(AndroidString(
+ kwargs.get('title').encode('utf-8')))
+ noti.setContentText(AndroidString(
+ kwargs.get('message').encode('utf-8')))
+ noti.setSmallIcon(icon)
+ noti.setAutoCancel(True)
+
+ if SDK_INT >= 16:
+ noti = noti.build()
+ else:
+ noti = noti.getNotification()
+
+ self._get_notification_service().notify(0, noti)
+
+
+def instance():
+ return AndroidNotification()
+