如何创建一个Android原生服务和使用粘结剂与它沟通? [英] How to Create a android native service and use binder to communicate with it?
问题描述
我的基本任务是建立在Android的原生服务,然后编写一个简单的本地程序进行测试。可以说,我想要写一个简单的服务,回报我的2个整数总和。我必须用粘合剂去跟它从程序,我试图谷歌左右,但我不能找到一个precise例子。我需要知道如何创建一个本地服务,并发现它的程序,如果需要在Java中也。
My basic task is to create a native service in android and then write a simple native program to test it. lets say i want to write a simple service which return me sum of 2 integers. I have to use binders to talk to it from the program, I have tried to google around but i cant find a precise example. I need to know how to create a native service and find it in the program and if needed in Java also.
请帮助我。 谢谢
推荐答案
这是我找到的解决方案是使用粘合剂在本地和使用
The solution that I found is to use the Binders in native and use the
defaultServiceManager()->addService(
String16("TestService"),new CalcService());
,然后下面的客户端使用的粘合剂和使用。
and then use binders and use following on client side.
sp<IServiceManager> sm = defaultServiceManager();
sp<IBinder> binder = sm->getService(String16("TestService"));
,我发现这里的例子就如何做到这一点: https://github.com/gburca/BinderDemo/blob/master/binder.cpp
I found examples here on how to do this: https://github.com/gburca/BinderDemo/blob/master/binder.cpp
这篇关于如何创建一个Android原生服务和使用粘结剂与它沟通?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!