Using JNI AndroidJNI.GetMethodID in unity with string parameters

I am working on unity with android javas plugin. I tried to call a 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 the code above, I was included to pass the int value to my java function and got the string value. When I try to pass a string value, it does not work for me. The problem here is because there is no string type in JNI

 jvalue[] myArray = new jvalue[1]; myArray[0].i =testvalue; 
+4
source share
3 answers

I decided it was a brother, and this is what I wanted myArray [0] .l = AndroidJNI.NewStringUTF (credentials);

0
source

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

+1
source

there is no string type in JNI

Yes there is. It is called "jstring".

0
source

Source: https://habr.com/ru/post/1416363/


All Articles