Did you mean calling java function from native code and calling native function from java code using JNI?
If yes i think i have the example you want (I integrate google play leaderboard and admob interstitial in my last T2 project).
However, right now i am a bit busy because my newest project is in the finishing stages so I'm only able to give you a few pointer right now.
If you're looking to implement google play leaderboards in T2 projects you should look at this example:
https://github.com/playgameservices/android-samples
Fore some JNI example, take a look at the Endless Tunnel project. Open the Tunnel directory and you will find jni directory. You might want to look at these files: jni_util, java_bgnactivity, java_ouractivity (both .cpp and .hpp) and the headers file in java_headers directory. I base my jni implementation from this project.
You will need to make a few changes though if you want to use these code in your agk project.
First you need to create your own launcher activity (AGK use nativeactivity by default)
public class YourNativeActivity extends NativeActivity implements ...
{
// Load the game's native code:
static {
System.loadLibrary("android_player");
}
}
and make changes on the manifest file so it launch this activity instead of NativeActivity then put the java function that you want to call in this activity class.
<activity android:name="com.blabla.bla.YourNativeActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode"
android:screenOrientation="sensorLandscape">
And in the jni_util files i make some changes so it can works in AppGameKit project:
extern "C" {
#include <jni.h>
#include <errno.h>
#include <android/log.h>
#include <android_native_app_glue.h>
#include <android/native_activity.h>
#include <unistd.h>
}
#include "jni_util.hpp"
extern ANativeActivity *g_pActivity;
static struct JniSetup _jni_setup = {0};
struct JniSetup* GetJNISetup() {
g_pActivity->vm->AttachCurrentThread(&_jni_setup.env, NULL);
_jni_setup.thiz = g_pActivity->clazz;
_jni_setup.clazz = _jni_setup.env->GetObjectClass(_jni_setup.thiz);
return &_jni_setup;
}
void ReleaseJNI()
{
g_pActivity->vm->DetachCurrentThread();
}
And as how to call the java function from native code, take a look at bgn_activity.cpp file. In short, it goes like this:
#include <jni.h>
#include <sys/atomics.h>
#include "java_bgnactivity.hpp"
#include "jni_util.hpp"
#include "template.h"
extern "C" {
#include <jni.h>
#include <errno.h>
#include <android/log.h>
#include <android_native_app_glue.h>
#include <android/native_activity.h>
#include <unistd.h>
}
void CustomActivity_ShowLeaderboards() {
struct JniSetup *setup = GetJNISetup();
jmethodID m_postShowLeaderboards = setup->env->GetMethodID(setup->clazz,
"postShowLeaderboards", "()V");
MY_ASSERT(m_postShowLeaderboards);
setup->env->CallVoidMethod(setup->thiz, m_postShowLeaderboards);
ReleaseJNI();
}
I think those are the important points to call java function from native code, i hope i don't miss anything important
Calling native function from java code is more complicated though.