Created
September 6, 2017 18:53
-
-
Save strazzere/d040b178c9409eef8ddd7a82258ae6a6 to your computer and use it in GitHub Desktop.
Example of calling android method from native code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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