using JNI AndroidJNI.GetMethodID in unity with string parameters

泪湿孤枕 提交于 2020-01-02 04:34:16

问题


I'm working on unity with android java plugin I was trying to call function from java in unity and it worked successfully.

        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(kdataActivityClass,"getURL","(I)Ljava/lang/String;");

        jvalue[] myArray = new jvalue[1];
        myArray[0].i =testvalue;
        gui.text=   AndroidJNI.CallStaticStringMethod(obj_Activity, startAdsMethod, myArray);

Using above code, I was enable to pass int value to my java function and recieve string value . When I'm trying to pass a string value, it's not working for me. The problem is somewhere here because there is no string type in JNI

jvalue[] myArray = new jvalue[1];
myArray[0].i =testvalue;

回答1:


The data type you are looking for is jstring and in JNI you can create it using newString or newStringUTF




回答2:


i solved it brother and this is what i wanted myArray[0].l=AndroidJNI.NewStringUTF(credentials);




回答3:


there is no string type in JNI

Yes there is. It's called 'jstring'.



来源:https://stackoverflow.com/questions/10914479/using-jni-androidjni-getmethodid-in-unity-with-string-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!