http://davanum.wordpress.com/2007/12/09/android-invoke-jni-based-methods-bridging-cc-and-java/
[]'s
Hamilton Vera
2010/10/20 Samuel Skånberg <dt0...@student.lth.se>:
> --
> unsubscribe: android-porti...@googlegroups.com
> website: http://groups.google.com/group/android-porting
>
--
Hamilton Vera
int Administrator (char Network[],char ComputationalSystems[])
http://hvera.wordpress.com
Thanks for you quick response!
In another post a developer asked how one should go about to publish an
IBinder interface of a native service with the system manager. There you
said one should follow four steps
"1. Declares a shared user ID with the system process, and that its
components will run in the system process.
2. Has a Service component that implements your "system" service.
3. Has an intent receiver for BOOT_COMPLETED that, when run, starts the
service.
4. In the Service implementation publishes its IBinder interface with the
private ServiceManager API."
http://groups.google.com/group/android-porting/browse_thread/thread/f9a383ce949d1557
That seemed like the "right" way to do it because then it integrates
nicely with the rest of the android environment and is being started
automatically after boot.
I was successful doing the first 3 but can't get it to work with the 4th
and that's what I'm trying to figure out now. In your previous message you
said I should keep all the binder stuff in C++ but from the post I linked
to it seems that it's possible to have a java class that extends the
Service class but that the onBind method return the C++ Binder interface.
Have I understood it correctly? If so, how do I return the C++ Binder
interface? I have no idea.
> I would recommend keeping all of the Binder stuff in C++, and implementing
> your Java APIs as JNI calls on the C++ Binder interface. Until aidl can
> generate C++ stubs, I think it is easier than maintaining both C++ and
> Java
> interfaces.
>
> 2010/10/20 Samuel Sk�nberg <dt0...@student.lth.se>
>
>> Well, those links were about JNI. I don't think I should have to use
>> JNI, do you? My service is implemented in C++, linked with binder and
>> the client I want to connect with is a normal android app so I should
>> be able to do
>>
>>
>> -------------------------------------------------------------------------------------
>> Intent i = new Intent();
>> i.setClassName("com.example.cppservice",
>> "com.example.cppservice.PokeService");
>> if (bindService(i, clientConnection, Context.BIND_AUTO_CREATE)) {
>> Log.d(getClass().getSimpleName(), "bindService()");
>> } else {
>> Log.e(getClass().getSimpleName(), "Could not bindService()");
>> }
>>
>> -------------------------------------------------------------------------------------
>>
>> I have no problems compiling the C++ program, that works nicely with
>> the android build system and my Android.mk file. But for some reason,
>> when I run it, it won't show up among the other services in android.
>> Am I missing some fundamental piece, like hooking onto the android
>> systems ServiceManager or something similar?
>>
>>
>> On Oct 20, 5:06 pm, Hamilton Vera <hamilton.lis...@gmail.com> wrote:
>> > Maybe you can find some information here:
>> >
>> > http://www.google.com.br/url?sa=t&source=web&cd=5&ved=0CDwQFjAE&url=h...
>> >
>> > http://davanum.wordpress.com/2007/12/09/android-invoke-jni-based-meth...
>> >
>> > []'s
>> >
>> > Hamilton Vera
>> >
>> > 2010/10/20 Samuel Sk�nberg <dt05...@student.lth.se>:
>> android-porti...@googlegroups.com<android-porting%2Bunsu...@googlegroups.com>
>> > > website:http://groups.google.com/group/android-porting
>> >
>> > --
>> > Hamilton Vera
>> > int Administrator (char Network[],char ComputationalSystems[])
>> http://hvera.wordpress.com
>>
>> --
>> unsubscribe:
>> android-porti...@googlegroups.com<android-porting%2Bunsu...@googlegroups.com>
extern jobject javaObjectForIBinder(JNIEnv* env, const sp<IBinder>& val);
> 2010/10/20 Samuel Skånberg <dt0...@student.lth.se>
>
>> Well, those links were about JNI. I don't think I should have to use
>> JNI, do you? My service is implemented in C++, linked with binder and
>> the client I want to connect with is a normal android app so I should
>> be able to do
>>
>>
>> -------------------------------------------------------------------------------------
>> Intent i = new Intent();
>> i.setClassName("com.example.cppservice",
>> "com.example.cppservice.PokeService");
>> if (bindService(i, clientConnection, Context.BIND_AUTO_CREATE)) {
>> Log.d(getClass().getSimpleName(), "bindService()");
>> } else {
>> Log.e(getClass().getSimpleName(), "Could not bindService()");
>> }
>>
>> -------------------------------------------------------------------------------------
>>
>> I have no problems compiling the C++ program, that works nicely with
>> the android build system and my Android.mk file. But for some reason,
>> when I run it, it won't show up among the other services in android.
>> Am I missing some fundamental piece, like hooking onto the android
>> systems ServiceManager or something similar?
>>
>>
>> On Oct 20, 5:06 pm, Hamilton Vera <hamilton.lis...@gmail.com> wrote:
>> > Maybe you can find some information here:
>> >
>> > http://www.google.com.br/url?sa=t&source=web&cd=5&ved=0CDwQFjAE&url=h...
>> >
>> > http://davanum.wordpress.com/2007/12/09/android-invoke-jni-based-meth...
>> >
>> > []'s
>> >
>> > Hamilton Vera
>> >
>> > 2010/10/20 Samuel Skånberg <dt05...@student.lth.se>:
There is no ANativeService like, ANativeActivity right? Means it has
to be Service component in Java code right?
> 3. Has an intent receiver for BOOT_COMPLETED that, when run, starts the
> service.
Is it possible to publish an implementation through the <receiver> tag
in native app's AndroidManifest.xml
> 4. In the Service implementation publishes its IBinder interface with the
> private ServiceManager API."
I intend to implement a native service, and bind to it from a Java application.
I came across this post and the links within it, and got a bit confused.
I have some queries inline, also can I get some pointers on how to do this?
Also, as the author of the original post asks, is it possible to do
this without JNI?
regards
-Nitin
>
> http://groups.google.com/group/android-porting/browse_thread/thread/f9a383ce949d1557
>
> That seemed like the "right" way to do it because then it integrates
> nicely with the rest of the android environment and is being started
> automatically after boot.
>
> I was successful doing the first 3 but can't get it to work with the 4th
> and that's what I'm trying to figure out now. In your previous message you
> said I should keep all the binder stuff in C++ but from the post I linked
> to it seems that it's possible to have a java class that extends the
> Service class but that the onBind method return the C++ Binder interface.
>
> Have I understood it correctly? If so, how do I return the C++ Binder
> interface? I have no idea.
>
>
>
>> I would recommend keeping all of the Binder stuff in C++, and implementing
>> your Java APIs as JNI calls on the C++ Binder interface. Until aidl can
>> generate C++ stubs, I think it is easier than maintaining both C++ and
>> Java
>> interfaces.
>>
>> 2010/10/20 Samuel Skånberg <dt0...@student.lth.se>
>>
>>> Well, those links were about JNI. I don't think I should have to use
>>> JNI, do you? My service is implemented in C++, linked with binder and
>>> the client I want to connect with is a normal android app so I should
>>> be able to do
>>>
>>>
>>> -------------------------------------------------------------------------------------
>>> Intent i = new Intent();
>>> i.setClassName("com.example.cppservice",
>>> "com.example.cppservice.PokeService");
>>> if (bindService(i, clientConnection, Context.BIND_AUTO_CREATE)) {
>>> Log.d(getClass().getSimpleName(), "bindService()");
>>> } else {
>>> Log.e(getClass().getSimpleName(), "Could not bindService()");
>>> }
>>>
>>> -------------------------------------------------------------------------------------
>>>
>>> I have no problems compiling the C++ program, that works nicely with
>>> the android build system and my Android.mk file. But for some reason,
>>> when I run it, it won't show up among the other services in android.
>>> Am I missing some fundamental piece, like hooking onto the android
>>> systems ServiceManager or something similar?
>>>
>>>
>>> On Oct 20, 5:06 pm, Hamilton Vera <hamilton.lis...@gmail.com> wrote:
>>> > Maybe you can find some information here:
>>> >
>>> > http://www.google.com.br/url?sa=t&source=web&cd=5&ved=0CDwQFjAE&url=h...
>>> >
>>> > http://davanum.wordpress.com/2007/12/09/android-invoke-jni-based-meth...
>>> >
>>> > []'s
>>> >
>>> > Hamilton Vera
>>> >
>>> > 2010/10/20 Samuel Skånberg <dt05...@student.lth.se>:
On Saturday, October 23, 2010, Dianne Hackborn <hac...@android.com> wrote:
> The Java runtime has wrappers around C++ IBinder. This is what Java's Binder is. You can write a JNI function that returns a Java Binder and in its implementation instantiate a C++ IBinder interface and return it. You will need to use this magic function in libandroid_runtime to do this:
>
> extern jobject javaObjectForIBinder(JNIEnv* env, const sp<IBinder>& val);
>
I was able to do it this way, I wil post the link to github for reference.