Android java插件调用方法返回零

时间:2012-06-05 10:51:58

标签: java android unity3d

我正在使用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); =>返回值 Debug.Log("kdataActivityClass"+kdataActivityClass); =>返回=>值
Debug.Log("Method"+startAdsMethod); => retunns null< ===这是此方法的问题

应该返回一个硬编码的字符串,但它不能统一工作。

非常感谢帮助。 感谢

1 个答案:

答案 0 :(得分:0)

使用javap检查getURL方法jni签名(您是否将相同的内容添加到第三个参数?):

cd <pathToUnityUrlPluginClass>

javap -p -s <UnityUrlPlugin>