Hi,
I have an NDK executable written in C and built with "include $
(BUILD_EXECUTABLE)". It works well, but I need access to Android
API's in order to test for network connectivity, etc. I have tried
writing a JNI bridge. This was a lot of work, but in the end I can
access my Java class. The general idea is to use the
ConnectivityManager to check if NetworkInfo.isConnected() and return
the result back to the C code.
Of course I can't call Context.getSystemService() without a Context.
And since my VM was launched from Native C rather than from Zygote or
whatever really happens under the hood, I don't have ready access to a
Context. This is ye olde "How can I get a static Context???"
problem.
Does anybody see any way around this? I don't know enough about what
happens behind the scenes to know if this is a complete dead end or
whether there is some other avenue I can try.
NB:
- Yes, I really do have a good business rational for doing this.
- No, for many business and technical reasons I cannot port my C
application to Java.
Thanks,
Ryan
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
I have an NDK executable written in C and built with "include $
(BUILD_EXECUTABLE)". It works well, but I need access to Android
API's in order to test for network connectivity, etc. I have tried
writing a JNI bridge. This was a lot of work, but in the end I can
access my Java class.
The general idea is to use the
ConnectivityManager to check if NetworkInfo.isConnected() and return
the result back to the C code.
Well, congratulations on accomplishing something technically interesting. But why do you have to do it this way?
Couldn't you let android create your process in the ordinary fashion and then run your native code in its own thread, mostly ignorant of the fact that it has a dalvik vm and binder worker threads and all sharing its process space, up until the time when you actually need to use those to proxy things to the framework for you? Yes, this seems wasteful (though much of the memory should be shared maps) but it's unfortunately the only model supported.
I am trying to reduce the memory footprint of an application that will be installed by the handset manufacturer (i.e. it is not an end-user application and it interacts with the device hardware on some level). This application is almost always idle, except for a few brief periods where it does something useful.
Thanks for your insights.
Cheers,
Ryan
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/JCEEQMUUNoEJ.
For what is worth, what you're describing should better be implemented by a daemon started/controlled through init.rc, which communicates with a service running inside the "system" VM process (see frameworks/base/services/java/com/android/server/ for existing ones). This definitely doesn't look like an "application".
For what is worth, what you're describing should better be implemented by a daemon started/controlled through init.rc, which communicates with a service running inside the "system" VM process (see frameworks/base/services/java/com/android/server/ for existing ones). This definitely doesn't look like an "application".
Very interesting. Just to clarify, when you say communicate, do you mean using pipes/other IPC or is there some other Android-esque way of doing this that I don't know about?
Thanks,
Ryan
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/yebxpVL4WP4J.
Dan
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.