0

I have this array of jvalue type and I want to assign string values.

I'm on unity trying to pass parameters to my Java function using JNI library

  jvalue[] myArray = new jvalue[2];
        myArray[0]="abcd";
        myArray[1]="khan";
        gui.text=   AndroidJNI.CallStaticStringMethod(obj_Activity, startAdsMethod, myArray);

How to achieve the code above?

I'm getting the error whilst assigning values to the array because the array is not of string type my function takes string parameters and jni wants them in form of array.

1

1 Answer 1

1

The following code creates an array and assigns a few strings to use in any following JNI calls:

var arguments = new object[2];
foreach( var entry in variables ) {
    using( var key = new AndroidJavaObject( "java.lang.String", entry.Key ) ){
        using( var val = new AndroidJavaObject( "java.lang.String", entry.Value ) ){
            arguments[0] = key;
            arguments[1] = val;
                    [... do something with the array ...]
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.