Skip to content

Instantly share code, notes, and snippets.

@MaximAlien
Created April 22, 2015 09:19
Show Gist options
  • Save MaximAlien/c3da4a62cf7476fbf4ae to your computer and use it in GitHub Desktop.
Save MaximAlien/c3da4a62cf7476fbf4ae to your computer and use it in GitHub Desktop.
[Android] [JNI] Method to get class name as std::string
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;
}
@rehmanmuradali
Copy link

IT returns java.lang.class . I want my class Name for example "MyClass"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment