问题
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