C ++ method call (cocos2dx) from java (android) for my billing in application

I am trying to add billing in an application in my cocos2dx-android project. I can give a java function call from a C ++ class via jni.

So I will call the java function through jni.

JniMethodInfo t; JniHelper::getStaticMethodInfo(t , "com/test/project/Project" , "BuyProduct" , "(Ljava/lang/String;)V"); char buffer[20]; sprintf(buffer,"product1"); jstring StringArg1 = t.env->NewStringUTF(buffer); t.env->CallStaticVoidMethod(t.classID, t.methodID, StringArg1); 

Billing in the application works fine, but now I need to give an answer to my C ++ class to find out whether the product was successfully purchased or not.

I could return the result of the called method only by indicating the specified type of return value, but the in-app process, which is an asynchronous process, goes through many method calls, and my control does not return back to the same method, so returning the value will not work.

So, is there any other way to pass the value (in my case, the result of the purchase in the application) for my C ++ class from a java function ???

+4
source share
1 answer

check the cocos2dxHelper.cpp file to see how the cocos2dx method calls the C ++ method. basically there is a method in cocos2dxHelper.java that has only a definition but not an implementation, it usually looks like

 public static native blahblah(); 

and the corresponding function in the cpp file is called

 Java_org_cocos2dx_cocos2dxHelper_blahblah() 

if you call blahblah() in Java code using runOnUIThread (), the C ++ function

 Java_org_cocos2dx_cocos2dxHelper_blahblah() 

will be called.

By the way, C ++ code should be something extern C { }

+3
source

Source: https://habr.com/ru/post/1483154/


All Articles