Issue
I have a purely native Android app, where the entry point is:
void android_main(struct android_app* state)
{
}
I need to access device information such as, android.os.Build.MODEL and in my android_main, have the following:
JNIEnv *env = state->activity->env;
jclass build_class = env->FindClass("android/os/Build");
jfieldID brand_id = env->GetStaticFieldID(build_class, "MODEL", "Ljava/lang/String;");
jstring brand_obj = (jstring)env->GetStaticObjectField(build_class, brand_id);
const char *nativeString = env->GetStringUTFChars(brand_obj, 0);
Unfortunately it crashes at the second line - "FindClass". I know that env
is not null because I checked for this, but otherwise I am unable to debug this and find out why it is crashing :(
Solution
Turns out I had to:
state->activity->vm->AttachCurrentThread(&env, NULL);
instead of
JNIEnv *env = state->activity->env;
This post was helpful: http://blog.tewdew.com/post/6852907694/using-jni-from-a-native-activity
Answered By - lost_bits1110
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.