0

Is it possible to bind java services in pure native code? Essentially, calling this part of code in under native C code

Intent i = new Intent(); 
i.setClassName("com.example.fooservice", 
    "com.example.fooservice.service"); 
bindService(i, clientConnection, Context.BIND_AUTO_CREATE);
Onik
  • 19,396
  • 14
  • 68
  • 91
xuguo
  • 1,816
  • 1
  • 11
  • 15

1 Answers1

1

No, not directly. However, you could accomplish it calling up to your NativeActivity via JNI.

Larry Schiefer
  • 15,687
  • 2
  • 27
  • 33
  • I think the tricky part for that is to get the clientConnection's callbacks, is that doable via JNI as well? – xuguo Mar 09 '16 at 03:08
  • Also, why android won't allow native code to access java android service.. that seems a very reasonable thing to do if you are writing a native app.. – xuguo Mar 09 '16 at 03:23
  • Android's dev model is to use the runtime, which provides a standardized way for apps to be entered and controlled. Even "native" apps are wrapped in a runtime (the `NativeActivity` is a thin form of `Activity` which knows to call your native code based on your meta data.) The framework provided APIs written in Java are more extensive and robust than native code. The `ServiceConnection` callback is tricky and you wouldn't be able to directly do it in native code. You'd have to extend `NativeActivity` and write your own to "hook" to get down via JNI to your native code. – Larry Schiefer Mar 09 '16 at 11:41