Created
April 22, 2015 09:19
-
-
Save MaximAlien/c3da4a62cf7476fbf4ae to your computer and use it in GitHub Desktop.
[Android] [JNI] Method to get class name as std::string
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
static std::string getClassName(JNIEnv *env, jobject entity, jclass clazz) | |
{ | |
jmethodID mid = env->GetMethodID(clazz, "getClass", "()Ljava/lang/Class;"); | |
jobject clsObj = env->CallObjectMethod(entity, mid); | |
jclass clazzz = env->GetObjectClass(clsObj); | |
mid = env->GetMethodID(clazzz, "getName", "()Ljava/lang/String;"); | |
jstring strObj = (jstring)env->CallObjectMethod(clsObj, mid); | |
const char* str = env->GetStringUTFChars(strObj, NULL); | |
std::string res(str); | |
env->ReleaseStringUTFChars(strObj, str); | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IT returns java.lang.class . I want my class Name for example "MyClass"