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

creating new service does not start the service #270

Closed
aoncorici opened this issue Sep 19, 2014 · 5 comments
Closed

creating new service does not start the service #270

aoncorici opened this issue Sep 19, 2014 · 5 comments

Comments

@aoncorici
Copy link

Dear all,

I would like to create a new service that starts when PythonService starts.
What I did was to create an aidl, java class to implement the Service interface and extend the Stub in the same package as PythonService.

I modified the manifest xml template to expose the service in the same process as PythonService, but still the service is not started.

When using the same code in another pure Java application the service starts well, a client can bind to it.

Can you tell me what key steps am I missing.

Thanks in advance for your help.

Ancuta Corici

@aoncorici
Copy link
Author

I tried also to retrieve a Binder to the PythonService and did not work...maybe it is a problem of naming in the manifest. Can you tell me what could be the problem.

@FeralBytes
Copy link
Contributor

Can you show the code that you used to do this in Java and the code that failed for you in Python? Also at this time I do not know if it is possible the android.Service class was written a long time ago and needs much improvement to make it more like a real service, but Pyjinus may enable such changes. Also what do you mean by different packages? Different Apps, I would think that is possible.

@aoncorici
Copy link
Author

Thank you for the answer. Yes, I am using Pyjnius. In the end the incompatibility/problem was that I was trying to create an AIDL service from another package than org.renpy.android. I had a deeper look but I got stuck in the way PythonService is initialized. In order to reproduce the environmental setting it would have taken me at lot of time and was not sure it was going to work. In the end I did not change the manifest as I decided to use a service exposed to bind operation from the PythonService, which is not exposing such a service originally. It would have been nice to have something plug and play.

@FeralBytes
Copy link
Contributor

Hey that sounds cool, would you share your Pyjnius code to start the additional service?

@aoncorici
Copy link
Author

I guess I can resume the tricky part as:
27 public static IBinder serviceBinder=null;
28
29 @OverRide
30 public IBinder onBind(Intent arg0) {
31 Log.v("python service", "onBind returning serviceBinder");
32 return serviceBinder;
33 }
34
35 public static void setBinder(IBinder binder){
36 serviceBinder = binder;
37 }

The trick is to set the binder in the PythonService from Java/Pyjnius and then implement your own Binder. The AIDL files were compiled nicely. There was another problem when the AIDL is complicated and contains classes that are not inside your project. For that I used in the build line the option --add-jar to include the library containing those compiled Java classes.

If you are wondering whre is this used, I am working on the non-open source project OpenMTC:
http://www.openmtc.org/
Thanks to Python-for-Android we have now our platform running on Android for getting data from sensors, sending commands (from the local device or from a device management server) to them and manage the connectivity of the device (locally or from a LWM2M device management server).

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

No branches or pull requests

2 participants