def notify(title='', message='', id=0, timeout=10, priority=None, defaults=False): icon = getattr(Drawable, 'icon') noti = NotificationBuilder(activity) if defaults: noti.setDefaults(autoclass('android.app.Notification').DEFAULT_ALL) noti.setContentTitle(String(title.encode('utf-8'))) noti.setContentText(String(message.encode('utf-8'))) noti.setSmallIcon(icon) noti.setAutoCancel(True) if priority is not None: noti.setPriority(priority) intent = activity.getPackageManager().getLaunchIntentForPackage( 'org.jtc.planilla') noti.setContentIntent(PendingIntent.getActivity(activity, 0, intent, 0)) activity.getSystemService(Context.NOTIFICATION_SERVICE).notify( id, noti.build())
def wake_app(): Logger.info("%s: wake_app %s" % (APP, datetime.now())) wl.acquire() intent = activity.getPackageManager().getLaunchIntentForPackage( 'org.jtc.planilla') Logger.debug("%s: Starting %s %s" % (APP, intent.toString(), datetime.now())) activity.startActivity(intent)
def wake_app(): Logger.info("%s: wake_app %s" % (APP, datetime.now())) wl.acquire() intent = activity.getPackageManager().getLaunchIntentForPackage( 'org.jtc.planilla') Logger.debug("%s: Starting %s %s" % (APP, intent.toString(), datetime.now())) activity.startActivity(intent)
def notify(title='', message='', id=0, timeout=10, priority=None, defaults=False): icon = getattr(Drawable, 'icon') noti = NotificationBuilder(activity) if defaults: noti.setDefaults(autoclass('android.app.Notification').DEFAULT_ALL) noti.setContentTitle(String(title.encode('utf-8'))) noti.setContentText(String(message.encode('utf-8'))) noti.setSmallIcon(icon) noti.setAutoCancel(True) if priority is not None: noti.setPriority(priority) intent = activity.getPackageManager().getLaunchIntentForPackage( 'org.jtc.planilla') noti.setContentIntent(PendingIntent.getActivity(activity, 0, intent, 0)) activity.getSystemService(Context.NOTIFICATION_SERVICE).notify( id, noti.build())
# coding=utf-8 """ Flash ----- """ from plyer.facades import Flash from jnius import autoclass from plyer.platforms.android import activity Camera = autoclass("android.hardware.Camera") CameraParameters = autoclass("android.hardware.Camera$Parameters") SurfaceTexture = autoclass("android.graphics.SurfaceTexture") PackageManager = autoclass('android.content.pm.PackageManager') pm = activity.getPackageManager() flash_available = pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH) class AndroidFlash(Flash): _camera = None def _on(self): if self._camera is None: self._camera_open() if not self._camera: return self._camera.setParameters(self._f_on) def _off(self): if not self._camera: return
import plyer 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())) Intent = autoclass('android.content.Intent') NotificationClass = autoclass('android.app.Notification') PendingIntent = autoclass('android.app.PendingIntent') notificationIntent = activity.getPackageManager().getLaunchIntentForPackage( activity.getPackageName()) notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP) intent = PendingIntent.getActivity(activity, 0, notificationIntent, 0) 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')))