我正在使用android java插件来统一调用我的java函数,如下所示:
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);
}
问题是我正在访问该类,但该类的方法返回 null
Debug.Log("obj_Activity"+obj_Activity);
=>retuns value
Debug.Log("kdataActivityClass"+kdataActivityClass);
=>returns =>value
Debug.Log("Method"+startAdsMethod);
=>retunns null <=== 这是这个方法的问题
应该返回一个硬编码的字符串,但它不能统一工作。
高度赞赏帮助。谢谢