Skip to content

Instantly share code, notes, and snippets.

@strazzere
Created September 6, 2017 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save strazzere/d040b178c9409eef8ddd7a82258ae6a6 to your computer and use it in GitHub Desktop.
Save strazzere/d040b178c9409eef8ddd7a82258ae6a6 to your computer and use it in GitHub Desktop.
Example of calling android method from native code
void Log(std::string s){
JNIEnv *env;
g_JavaVM->GetEnv((void**)&env, JNI_VERSION_1_6);
jstring jstr1 = env->NewStringUTF(s.c_str());
jclass clazz = env->FindClass("diff/strazzere/secret/method");
// Later part is dalvik notation for parameters and return value, string param and void return value here
jmethodID mid = env->GetStaticMethodID(clazz, "methodname", "(Ljava/lang/String;)V");
jobject obj = env->CallStaticObjectMethod(clazz, mid, jstr1);
}
//In some initialization function with Environment variable
env->GetJavaVM(&g_JavaVM);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment