In the android_app
structure there's a data member called activity
of type ANativeActivity*
. Inside the latter, there's a JavaVM *vm
and a misleadingly called jobject clazz
. The clazz
is actually a JNI-compliant object instance pointer to a Java object of type android.app.NativeActivity
, which has all Activity
methods, including getIntent()
.
There's a JNIEnv
there, too, but it looks like it's not attached to the activity's main thread.
Use JNI invokations to retrieve the intent, then extras from the intent. It goes like this:
JNIEnv *env;
state->activity->vm->AttachCurrentThread(&env, 0);
jobject me = state->activity->clazz;
jclass acl = env->GetObjectClass(me); //class pointer of NativeActivity
jmethodID giid = env->GetMethodID(acl, "getIntent", "()Landroid/content/Intent;");
jobject intent = env->CallObjectMethod(me, giid); //Got our intent
jclass icl = env->GetObjectClass(intent); //class pointer of Intent
jmethodID gseid = env->GetMethodID(icl, "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
jstring jsParam1 = (jstring)env->CallObjectMethod(intent, gseid, env->NewStringUTF("MY_PARAM_1"));
const char *Param1 = env->GetStringUTFChars(jsParam1, 0);
//When done with it, or when you've made a copy
env->ReleaseStringUTFChars(jsParam1, Param1);
//Same for Param2
state->activity->env
as is, or have I to acquire it usingstate->activity->vm->AttachCurrentThread(&env, 0);
? – Nisa