Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void onIncrementAchievement(unsigned char _iArgumentCount, const void *_pArguments, void *_pUserData){
- JNIEnv *pJNIEnv = GetJNIEnv();
- if (pJNIEnv){
- if ( _pArguments && ( _iArgumentCount > 0 ) ){
- const S3DX::AIVariable *pVariables = (const S3DX::AIVariable *)_pArguments ;
- for ( uint8_t i = 0 ; i < _iArgumentCount ; i++ ){
- //We only want strings
- if(pVariables[i].GetType() == S3DX::AIVariable::eTypeString){
- //LOGI( "incrementAchievement returned string: %s", pVariables[i].GetStringValue() );
- //Find our main class so we can call the incrementAchievement function. For me, my package name is:
- //com.hypercanestudios.acceleroketer
- //within that package I have a class called accelerocketer
- //so <package name>/<class name> and replace "." with "/"
- // CHANGE ME!
- jclass pJNIActivityClass = pJNIEnv->FindClass ( "com/nurfacegames/testgame01/TestGame01" );
- if(pJNIActivityClass == NULL)
- LOGI("jclass was null!?!");
- else{
- //Now we have to find the function we're trying to call. We use the class defined above since the function
- //is a member of that class. (Ljava/lang/String;) is the set of arguments that the function takes, a single String
- //V means that the function returns void
- //void incrementAchievement(String blah)
- //See table 3-2 http://docs.oracle.com/javase/1.3/docs/guide/jni/spec/types.doc.html#597
- jmethodID pJNIMethodID = pJNIEnv->GetStaticMethodID(pJNIActivityClass, "onIncrementAchievement", "(Ljava/lang/String;)V", "(Ljava/lang/Integer;)V" );
- if(pJNIMethodID == NULL)
- LOGI("jmethodID was null!?!?");
- else{
- //Create a new string
- jstring arg;
- arg = pJNIEnv->NewStringUTF(pVariables[i].GetStringValue());
- jint arg2 = pVariables[1].GetNumberValue();
- if(arg2 == NULL)
- LOGI("ARGUMENT MISSING!!");
- else{
- //Call the method and pass the string parameter along
- pJNIEnv->CallStaticVoidMethod(pJNIActivityClass, pJNIMethodID, arg, arg2);
- //Free the string
- pJNIEnv->DeleteLocalRef(arg);
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement