I have these two code snippets, the two display the same result, so I would like to know what the difference is between them.
1
jclass cls = (*env)->FindClass(env, "android/content/ContextWrapper");
jmethodID mid = (*env)->GetMethodID(env, cls, "getPackageName", "()Ljava/lang/String;");
jstring packageNamei = (jstring)(*env)->CallObjectMethod(env, context, mid);
const char *nativeString = (*env)->GetStringUTFChars(env, packageNamei, 0);
__android_log_print(ANDROID_LOG_INFO, "--packageName--jni--", "%s", nativeString);
2
jclass context_clazz = (*env)->GetObjectClass(env, context);
jmethodID methodID_pack = (*env)->GetMethodID(env, context_clazz,
"getPackageName", "()Ljava/lang/String;");
jstring application_package = (*env)->CallObjectMethod(env, context, methodID_pack);
const char *str = (*env)->GetStringUTFChars(env, application_package, 0);
__android_log_print(ANDROID_LOG_DEBUG, "JNI", "PackageName: %s\n", str);
Can I use any of them, or is one more recommended?