Shoaib Ahmed
Shoaib Ahmed

Reputation: 781

JNI values assignment to array

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.

Upvotes: 0

Views: 405

Answers (1)

ADB
ADB

Reputation: 2329

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 ...]
        }
    }
}

Upvotes: 1

Related Questions