Skip to content

Commit cb94ed5

Browse files
committed
Enhance testapp_service: add a service as specified in docs
1 parent bc06cc8 commit cb94ed5

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

testapps/setup_testapp_service.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from setuptools import find_packages
44

55
options = {'apk': {'debug': None,
6-
'requirements': 'python2,genericndkbuild',
6+
'requirements': 'python2,genericndkbuild,pyjnius',
77
'android-api': 27,
88
'ndk-api': 21,
99
'ndk-dir': '/home/asandy/android/crystax-ndk-10.3.2',
@@ -12,6 +12,7 @@
1212
'bootstrap': 'service_only',
1313
'permissions': ['INTERNET', 'VIBRATE'],
1414
'arch': 'armeabi-v7a',
15+
'service': 'time:p4atime.py',
1516
}}
1617

1718
package_data = {'': ['*.py']}
@@ -21,7 +22,7 @@
2122

2223
setup(
2324
name='testapp_service',
24-
version='1.0',
25+
version='1.1',
2526
description='p4a service testapp',
2627
author='Alexander Taylor',
2728
author_email='[email protected]',

testapps/testapp_service/main.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
print('main.py was successfully called')
1+
print('Service Test App main.py was successfully called')
22

33
import sys
44
print('python version is: ', sys.version)
@@ -11,17 +11,9 @@
1111
print(i, sqrt(i))
1212

1313
print('Just printing stuff apparently worked, trying a simple service')
14-
import datetime, threading, time
1514

16-
next_call = time.time()
17-
18-
19-
def service_timer():
20-
global next_call
21-
print('P4a datetime service: {}'.format(datetime.datetime.now()))
22-
next_call = next_call + 1
23-
threading.Timer(next_call - time.time(), service_timer).start()
24-
25-
26-
print('Starting the service timer...')
27-
service_timer()
15+
from jnius import autoclass
16+
service = autoclass('org.test.testapp_service.ServiceTime')
17+
mActivity = autoclass('org.kivy.android.PythonActivity').mActivity
18+
argument = 'test argument ok'
19+
service.start(mActivity, argument)

testapps/testapp_service/p4atime.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import datetime
2+
import threading
3+
import time
4+
from os import environ
5+
argument = environ.get('PYTHON_SERVICE_ARGUMENT', '')
6+
print('p4atime.py was successfully called with argument: "{}"'.format(argument))
7+
8+
next_call = time.time()
9+
10+
11+
def service_timer():
12+
global next_call
13+
print('P4a datetime service: {}'.format(datetime.datetime.now()))
14+
next_call = next_call + 1
15+
threading.Timer(next_call - time.time(), service_timer).start()
16+
17+
18+
print('Starting the service timer...')
19+
service_timer()

0 commit comments

Comments
 (0)