kivy / kivy/oscpy

Activity and Service don't respond to messages from one another on Android

Open
#58 2 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Python
Stars
114
Forks
26
PR merge metrics
No merged PRs in 30d

Description

The code works on mac, but on an Android device it seems that the service and main app don't exchange (respond to) messages from one another.
Because if I don't send messages between them and just start service and push notification on a time interval it works.
Below is my code.

main.py:
```
from oscpy.client import OSCClient
from oscpy.server import OSCThreadServer

SERVICE_NAME = '{packagename}.Service{servicename}'.format(
packagename='clientsandorders.com.clientsandorders',
servicename='Taskreminder'
)

class MainApp(MDApp):
def build(self):
kv = Builder.load_file("main.kv")

self.start_service()

self.server = server = OSCThreadServer()
server.listen(
address=b'localhost',
port=3002,
default=True,
)

server.bind(b'/ping_response', self.ping_response)
self.client = OSCClient(address=b'localhost', port=3000)

return kv

def ping_response(self):
self.client.send_message(b'/push_up', [])
```

And here's the service code:

```
from time import sleep
from oscpy.server import OSCThreadServer
from oscpy.client import OSCClient
from plyer import notification
from plyer.utils import platform
from jnius import autoclass

CLIENT = OSCClient(address='localhost', port=3002)

def push_up():
if platform == 'android':
notification.notify(title='Test', message='This is a test message')
else:
print('Service works')

def ping_activity():
CLIENT.send_message(b'/ping_response', [])

if __name__ == '__main__':
SERVER = OSCThreadServer()
SERVER.listen(address='localhost', port=3000, default=True)
SERVER.bind(b'/push_up', push_up)
PythonService = autoclass('org.kivy.android.PythonService')
PythonService.mService.setAutoRestartService(True)

while True:
sleep(10)
ping_activity()
```

Expected behaviour is for service to ping the main app on a specific time interval, then get a response (with some data in the future) and to push a notification with plyer.

logcat shows no errors.

Many thanks in advance!

Contributor guide

Open the contributing guide

Research direction

Start with main.py and the service code shown, then compare the localhost listeners, ports, and message handlers used by the activity and service. Run the app and service on Android while inspecting logcat; done means they exchange messages in both directions and the service can trigger the notification.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, python
Domain
mobile-dev, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.