Coder Social home page Coder Social logo

kivy_service_osc's Introduction

Purpose

CircleCI

This code aims at demonstrating an use of services in python-for-android, and communication between services and a kivy front end.

That examples uses the OSC protocol for simplicity and historical reasons, (since an implementation was shipped with kivy historically, and a better one is now found in oscpy). The OSC protocol makes things simple because it's unconnected, you just send a message, and can forget about it. You bind functions to messages you receive. It's simple enough for a lot of things, and avoids the burden of maintaining a connection when both the service and front end can be restarted any time.

The app is composed of the front-end, defined in src/main.py, and the back-end defined in src/service.py.

The service (back-end):

  • is defined in buildozer.spec, in the services line. Following the example syntax
  • is started by the application at startup time, and can be stopped/restarted from the UI.
  • sends the current date, as a string, every tenth of a second to the UI, on a '/date' address.
  • answers with a random string on the '/message' address when a message is sent to the '/ping' address on its side.

The UI (front-end):

  • is defined in main.py
  • allows stopping/restarting the backend.
  • displays the last received messages from the backend in a RecycleView
  • allow to sent a '/ping' message to the backend, which will trigger a new message.

Building:

  • The package is built using CircleCI, you should be able to download the latest debug apk by clicking on the "Artifacts" tab on the latest build.
  • This project is a template repository, so you can create your own project from it, and setup CircleCI to build your version of it.
  • You can also just run the kivy/buildozer docker image to build your project from any Linux computer.
docker run -v $PWD:/project/ -w /project/ kivy/buildozer android debug

Once it's completed, you should have a bin/ directory with the apk inside.

kivy_service_osc's People

Contributors

loan-mgt avatar true-learner avatar tshirtman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

kivy_service_osc's Issues

Is there a way to get the service alive?

When the phone goes to sleep or I change to other app for a while, Android kills the service. I get the following error

ActivityManager: Stopping service due to app idle u0a262 -1m55s386ms org.kivy.oscservice/.ServicePong

Is there a way to get the service alive in these situations?

Python modules in service.py

I can use only standard library of python in service.py
When I am using other python modules service being stop.

How can I change package name and package domain?

When I changed package.name = oscservice to package.name = BatteryProtector and package.domain = org.kivy to package.domain = org.ipfelec in buildozer.spec, app don't run. I also changed the following code, the app will not run.

 SERVICE_NAME = u'{packagename}.Service{servicename}'.format(
     packagename=u'org.ipfelec.BatteryProtect',
     servicename=u'Pong'
 )

This is my Error:

09-01 02:07:54.443  2162  2200 I python  :  Traceback (most recent call last):
09-01 02:07:54.443  2162  2200 I python  :    File "/media/mehdi/2436ef15-26cf-4be8-9eed-6befb73eddd8/mehdi/Documents/BuildozerTest/.buildozer/android/app/main.py", line 398, in <module>
09-01 02:07:54.443  2162  2200 I python  :    File "/media/mehdi/2436ef15-26cf-4be8-9eed-6befb73eddd8/mehdi/Documents/BuildozerTest/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/BatteryProtector/kivy/app.py", line 949, in run
09-01 02:07:54.444  2162  2200 I python  :    File "/media/mehdi/2436ef15-26cf-4be8-9eed-6befb73eddd8/mehdi/Documents/BuildozerTest/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/BatteryProtector/kivy/app.py", line 919, in _run_prepare
09-01 02:07:54.444  2162  2200 I python  :    File "/media/mehdi/2436ef15-26cf-4be8-9eed-6befb73eddd8/mehdi/Documents/BuildozerTest/.buildozer/android/app/main.py", line 317, in build
09-01 02:07:54.444  2162  2200 I python  :    File "/media/mehdi/2436ef15-26cf-4be8-9eed-6befb73eddd8/mehdi/Documents/BuildozerTest/.buildozer/android/app/main.py", line 334, in start_service
09-01 02:07:54.445  2162  2200 I python  :    File "/media/mehdi/2436ef15-26cf-4be8-9eed-6befb73eddd8/mehdi/Documents/BuildozerTest/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/BatteryProtector/jnius/reflect.py", line 208, in autoclass
09-01 02:07:54.445  2162  2200 I python  :    File "jnius/jnius_export_func.pxi", line 28, in jnius.jnius.find_javaclass
09-01 02:07:54.446  2162  2200 I python  :  jnius.jnius.JavaException: Class not found b'org/ipfelec/BatteryProtector/ServicePong'
09-01 02:07:54.446  2162  2200 I python  : Python for android ended.

Is it possible for me to change these names?

ImportError: cannot import name 'osc' from 'kivy.lib'

Hi, I'm new with kivy and wanted to run the kivy_service_osc example.
Yet, I get a "ImportError: No module named android". I have tried several things but always got this error and the kivy window does not appear.
my buildozer.spec has:
title = Kivy service OSC demo
package.name = serviceexample
package.domain = org.test
requirements = kivy
android.permissions = INTERNET
android.sdk = 20
android.ndk = 13b

I set NDK 13b because 9b isn't available anymore to download from Google.

I have attached the buildozer android logcat log from the respective process 3930

I don't know whether this is the right place to report my issue but didn't find another place.

Question : push notification or play sound from service?

Is it possible to push a notification or play a sound while the service and app are running in the background?
Any example or hint how to add this feature to the existing code : play a sound every minute?
Kind Regards, Hans

service crash with android_new toolchain

Hi!
On my device, this application crash as soon as it's started. Funny thing is that it happen just when the build is compiled through the "android_new" toolchain rather than the old "android".

I can't really say if the issue comes from the code or the toolchain, but commenting the line #48 (autostart of the service) the app open correctly. Then if I manually hit the button to "start service" appear crash pop-up: "Unfortunately, Kivy service OSC demo has stopped"

Should be indicated some other modules in buildozer when building with the android_new toolchain?
Thanks!

service.stop() fails

service.stop() fails on desktop and on Android for different reasons.

Desktop: threading.Thread() has no stop() method

Android, using the same buildozer.spec : pyjnius is not happy

11-05 16:51:41.447 30426 30460 I python  :  Traceback (most recent call last):
11-05 16:51:41.447 30426 30460 I python  :    File "/home/bobf/ex/service/.buildozer/android/app/main.py", line 116, in <module>
11-05 16:51:41.447 30426 30460 I python  :    File "/home/bobf/ex/service/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oscservice/kivy/app.py", line 855, in run
11-05 16:51:41.448 30426 30460 I python  :    File "/home/bobf/ex/service/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oscservice/kivy/base.py", line 504, in runTouchApp
11-05 16:51:41.448 30426 30460 I python  :    File "/home/bobf/ex/service/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oscservice/kivy/core/window/window_sdl2.py", line 747, in mainloop
11-05 16:51:41.448 30426 30460 I python  :    File "/home/bobf/ex/service/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oscservice/kivy/core/window/window_sdl2.py", line 479, in _mainloop
11-05 16:51:41.448 30426 30460 I python  :    File "/home/bobf/ex/service/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oscservice/kivy/base.py", line 342, in idle
11-05 16:51:41.449 30426 30460 I python  :    File "/home/bobf/ex/service/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oscservice/kivy/base.py", line 327, in dispatch_input
11-05 16:51:41.449 30426 30460 I python  :    File "/home/bobf/ex/service/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oscservice/kivy/base.py", line 233, in post_dispatch_input
11-05 16:51:41.449 30426 30460 I python  :    File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
11-05 16:51:41.449 30426 30460 I python  :    File "/home/bobf/ex/service/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oscservice/kivy/core/window/__init__.py", line 1402, in on_motion
11-05 16:51:41.449 30426 30460 I python  :    File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
11-05 16:51:41.450 30426 30460 I python  :    File "/home/bobf/ex/service/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oscservice/kivy/core/window/__init__.py", line 1418, in on_touch_down
11-05 16:51:41.450 30426 30460 I python  :    File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
11-05 16:51:41.450 30426 30460 I python  :    File "/home/bobf/ex/service/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oscservice/kivy/uix/widget.py", line 549, in on_touch_down
11-05 16:51:41.450 30426 30460 I python  :    File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
11-05 16:51:41.450 30426 30460 I python  :    File "/home/bobf/ex/service/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oscservice/kivy/uix/widget.py", line 549, in on_touch_down
11-05 16:51:41.451 30426 30460 I python  :    File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
11-05 16:51:41.451 30426 30460 I python  :    File "/home/bobf/ex/service/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oscservice/kivy/uix/behaviors/button.py", line 151, in on_touch_down
11-05 16:51:41.451 30426 30460 I python  :    File "kivy/_event.pyx", line 703, in kivy._event.EventDispatcher.dispatch
11-05 16:51:41.451 30426 30460 I python  :    File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
11-05 16:51:41.452 30426 30460 I python  :    File "kivy/_event.pyx", line 1098, in kivy._event.EventObservers._dispatch
11-05 16:51:41.452 30426 30460 I python  :    File "/home/bobf/ex/service/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/oscservice/kivy/lang/builder.py", line 64, in custom_callback
11-05 16:51:41.452 30426 30460 I python  :    File "<string>", line 12, in <module>
11-05 16:51:41.452 30426 30460 I python  :    File "/home/bobf/ex/service/.buildozer/android/app/main.py", line 100, in stop_service
11-05 16:51:41.452 30426 30460 I python  :    File "jnius/jnius_export_class.pxi", line 745, in jnius.jnius.JavaMethod.__call__
11-05 16:51:41.453 30426 30460 I python  :  jnius.jnius.JavaException: Invalid call, number of argument mismatch, got 0 need 1
11-05 16:51:41.453 30426 30460 I python  : Python for android ended.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.