5

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;
Programmer
  • 121,791
  • 22
  • 236
  • 328
Shoaib Ahmed
  • 747
  • 12
  • 28

3 Answers3

2

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

bobby
  • 2,629
  • 5
  • 30
  • 56
1

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

Shoaib Ahmed
  • 747
  • 12
  • 28
0

there is no string type in JNI

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

user207421
  • 305,947
  • 44
  • 307
  • 483