I’m using android java plugin to call my java function in unity like this:
static IntPtr cls_Activity;
static IntPtr fid_Activity;
static IntPtr obj_Activity;
static IntPtr kdataActivityClass;
static IntPtr startAdsMethod;
void Start () {
cls_Activity = AndroidJNI.FindClass("com/unity3d/player/UnityPlayer");
fid_Activity = AndroidJNI.GetStaticFieldID(cls_Activity, "currentActivity", "Landroid/app/Activity;");
obj_Activity = AndroidJNI.GetStaticObjectField(cls_Activity, fid_Activity);
kdataActivityClass = AndroidJNI.FindClass("com/kdata/unitytest/UnityUrlPlugin");
startAdsMethod = AndroidJNI.GetMethodID(PakdataActivityClass, "getURL","()V");
Debug.Log("obj_Activity"+obj_Activity);
Debug.Log("kdataActivityClass"+kdataActivityClass);
Debug.Log("Method"+startAdsMethod);
if (AndroidJNI.IsInstanceOf(obj_Activity, kdataActivityClass) != false)
{
jvalue[] myArray = new jvalue[1];
AndroidJNI.CallStaticStringMethod(obj_Activity, startAdsMethod, myArray);
}
The problem is that I am getting access to the class but method from the class is returns null
Debug.Log("obj_Activity"+obj_Activity); =>retuns value
Debug.Log("kdataActivityClass"+kdataActivityClass); =>returns =>value
Debug.Log("Method"+startAdsMethod); =>retunns null <=== here is the problem this method
Should return a hardcoded string but its not working in unity.
Help is highly appreciated.
Thanks
Check getURL method jni signature with javap (did you put the same to your third parameter ?) :