void launchJavaActivity(){
// Attaches the current thread to the JVM.
jint lResult;
jint lFlags = 0;
EngineAndroid * pEngine = (EngineAndroid*)Engine::InstancePtr();
JavaVM* lJavaVM = pEngine->GetNativeActivity()->vm; //<---- replace this with your NativeActivity pointer
JNIEnv *lJNIEnv = 0;
lResult=lJavaVM->AttachCurrentThread(&lJNIEnv,NULL);
if (lResult == JNI_ERR) {
return;
}
jobject lNativeActivity = pEngine->GetNativeActivity()->clazz;
jclass ClassNativeActivity = lJNIEnv->FindClass("android/app/NativeActivity");
jclass contextClass = lJNIEnv->FindClass("android/content/Context");
if(contextClass == 0)
return;
jmethodID startActivityMethodId = lJNIEnv->GetMethodID(contextClass, "startActivity", "(Landroid/content/Intent;)V");
if(startActivityMethodId == 0)
return;
jclass intentClass = lJNIEnv->FindClass("android/content/Intent");
if(intentClass == 0)
return;
jmethodID intentConstructorMethodId = lJNIEnv->GetMethodID(intentClass, "", "()V");
if(intentConstructorMethodId == 0)
return;
jmethodID intentSetActionMethodId = lJNIEnv->GetMethodID(intentClass, "setAction", "(Ljava/lang/String;)Landroid/content/Intent;");
if(intentSetActionMethodId == 0)
return;
jmethodID getClassLoader = lJNIEnv->GetMethodID(ClassNativeActivity,"getClassLoader", "()Ljava/lang/ClassLoader;");
if(getClassLoader == 0)
return;
jobject cls = lJNIEnv->CallObjectMethod(lNativeActivity, getClassLoader);
if(cls == 0)
return;
jclass classLoader = lJNIEnv->FindClass("java/lang/ClassLoader");
if(classLoader == 0)
return;
jmethodID findClass = lJNIEnv->GetMethodID(classLoader, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;");
if(findClass == 0)
return;
jstring intentString = lJNIEnv->NewStringUTF("ar.com.eudaimonia.JAVAACTIVITY);
if(intentString == 0)
return;
jclass marketActivityClass = (jclass)lJNIEnv->CallObjectMethod(cls, findClass, intentString);
if(marketActivityClass == 0)
return;
jobject intentObject = lJNIEnv->NewObject(intentClass,intentConstructorMethodId);
if(intentObject == 0)
return;
lJNIEnv->CallVoidMethod(intentObject, intentSetActionMethodId,intentString);
lJNIEnv->CallVoidMethod(lNativeActivity, startActivityMethodId, intentObject);
lJavaVM->DetachCurrentThread();
}
In the AndroidManifest.xml define your Java Activity :
<</span>activity android:name=".JAVAACTIVITY" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<</span>intent-filter>
<</span>action android:name="ar.com.eudaimonia.JAVAACTIVITY" />
<</span>category android:name="android.intent.category.DEFAULT" />
</</span>intent-filter>
</</span>activity>