Please carry me, I'm an iPhone developer, and this whole android bothers me a bit.
I have some C ++ methods that are called from cocos2d-x CCMenuItem. Therefore, I can not send any parameters according to the docs.
I need to open a URL with an Android browser that will require me to call the JAVA function in order to start a new intent.
I understand that I need to create a virtual machine, however the code below gives me an error:
jni /../../ Classes / ParametersScene.cpp: 184: error: 'JNI_CreateJavaVM' was not declared in this area
I watched this topic: Calling a java method from C ++ in Android
But it uses parameters, and I cannot do this. And I donโt see where they are in his code, just to make them yourself.
I donโt know what line should be in the Find Class method. Also, I suppose it's pretty terrible to create a new instance of a virtual machine in every method that I need to call. How can I create one singleton for use in all directions?
This is my C ++ code invoked by my menu item:
#include <jni.h> ... JavaVM *vm; // Global ... void OptionsScene::website(){ JNIEnv *env; JavaVMInitArgs vm_args; vm_args.version = JNI_VERSION_1_2; vm_args.nOptions = 0; vm_args.ignoreUnrecognized = 1; jint result = JNI_CreateJavaVM(&vm, (void **)&env, &vm_args); // This line still errors jclass clazz = env->FindClass("com/prndl/project/WebExecute"); jmethodID method = env->GetMethodID(clazz, "website", "(Ljava/lang/String;)V"); env->CallVoidMethod(NULL,method); vm->DestroyJavaVM();
And this is the JAVA method I need to call:
public class WebExecute extends Activity{ public void website(){ Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")); startActivity(browserIntent); } }
Honestly, I am struggling with this, any help is appreciated. Thanks.