I am trying to call into a Java class via C++/JNI on Android. More specifically, I am trying to call the constructor of this class which takes an Android Context as a parameter. I have no issue making the call successfully if my constructor has no params, but when I include the necessary Context as a parameter, I do not know what my JNI signature should look like and also doubt if that is even possible since I do not have access to that context object.
So, my question is, is it possible to call the constructor of a Java class which takes an Android Context as its only parameter ? If so, how ? If not, is there a workaround as I need the context to access certain Android API classes.
I dont believe its possible in the manner you stated. However, w/o knowing the structure of your class, you could always create it as a singleton w/ a static instance which gets instantiated on start up of your Activity, thereby the class attains the required context at that time. It would essentially sit there until you're ready to call in from C++, but would indeed be available to service your request w/ the context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With