I would like to get the context of application which has reference/hosted my library at run-time inside one class of my library project. Is it possible? If yes, how?
There's another way to get context in jni, neither passing a parameter nor saving context by yourself, but by using android api. I found that there's a class named:
in the source code. And the static function
getInitialApplication
can return an Application
object. But it must be called in main thread, and the class is hidden.
Anyway you can use it by reflecting in java. And you can just use FindClass()
and FindStaticObjectMethod()
to find out the method, and use it.
Hope that helps.