@@ -313,6 +313,72 @@ Please have a look into the code and you are very welcome to contribute to
313313this documentation.
314314
315315
316+ Android Service
317+ ---------------
318+
319+ Service part of the application is controlled through the class :class: `AndroidService `.
320+
321+ .. module :: android
322+
323+ .. class :: AndroidService(title, description)
324+
325+ Run ``service/main.py `` from application directory as a service.
326+
327+ :Parameters:
328+ `title `: str, default to 'Python service'
329+ Notification title.
330+
331+ `description `: str, default to 'Kivy Python service started'
332+ Notification text.
333+
334+ .. method :: start(arg)
335+
336+ Start the service.
337+
338+ :Parameters:
339+ `arg `: str, default to ''
340+ Argument to pass to a service,
341+ through environment variable ``PYTHON_SERVICE_ARGUMENT ``.
342+
343+ .. method :: stop()
344+
345+ Stop the service.
346+
347+ Application activity part example, ``main.py ``:
348+
349+ .. code-block :: python
350+
351+ from android import AndroidService
352+
353+ ...
354+
355+ class ServiceExample (App ):
356+
357+ ...
358+
359+ def start_service (self ):
360+ self .service = AndroidService(' Sevice example' , ' service is running' )
361+ self .service.start(' Hello From Service' )
362+
363+ def stop_service (self ):
364+ self .service.stop()
365+
366+ Application service part example, ``service/main.py ``:
367+
368+ .. code-block :: python
369+
370+ import os
371+ import time
372+
373+ # get the argument passed
374+ arg = os.getenv(' PYTHON_SERVICE_ARGUMENT' )
375+
376+ while True :
377+ # this will print 'Hello From Service' continually, even when application is switched
378+ print arg
379+ time.sleep(1 )
380+
381+
316382 How it's working without PyJNIus
317383--------------------------------
318384
0 commit comments