Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
olek5andr opened this issue Mar 9, 2021 · 2 comments
Labels
question Further information is requested

Comments

@olek5andr
Copy link

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!

@tshirtman
Copy link
Member

Sorry for not seeing this earlier, did you succeed? if not, did you try adding the INTERNET permission to your app in buildozer.spec or through p4a command line options?

@tshirtman tshirtman added the question Further information is requested label Apr 2, 2021
@olek5andr
Copy link
Author

Sorry for not seeing this earlier, did you succeed? if not, did you try adding the INTERNET permission to your app in buildozer.spec or through p4a command line options?

Yeah, I had the INTERNET permission in my buildozer.spec. I've kinda found a workaround for my project, I just launch the service from the main app, but don't exchange any data between them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants