-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
48 lines (38 loc) · 1.18 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.utils import platform
KV = '''
BoxLayout:
id: box
orientation: "vertical"
spacing: 15
MDToolbar:
title: "Kivy Service Demo"
MDRaisedButton:
id: mybutton
pos_hint: {"center_x": 0.5, "center_y": 0.5}
text: "Send Push Notification"
on_press: app.button_pressed()
MDLabel:
id: mylabel
halign: "center"
text: ""
'''
class Main(MDApp):
def build(self):
return Builder.load_string(KV)
def on_start(self):
if platform == 'android':
from jnius import autoclass
service = autoclass('org.test.myapp.ServiceMyservice')
mActivity = autoclass('org.kivy.android.PythonActivity').mActivity
argument = ''
service.start(mActivity, argument)
label = self.root.ids.mylabel
label.text += "\nservice started"
def button_pressed(self):
import plyer
plyer.notification.notify(title='Button pressed', message="Notification using plyer")
label = self.root.ids.mylabel
label.text += "\npush notification sent"
Main().run()