Pass javascript array type to java function in react native

Viewed 725

I'm working on a mobile app with React Native.

I have a native java function which receive an int array as argument:

@ReactMethod
public void createImage(int[] pixels, int width, int height, Callback callback) {
    Integer eventId = 10;
    Bitmap bmp = getBitmap(pixels, width, height);
    String res = convert(bmp);
    callback.invoke(res);
}

I call this function from my react native code like this:

var array = [];
for(let i = 0; i < 256*256; i++)
{
    array.push(i%256);
}

CalendarModule.createCalendarEvent(
    array,
    256,
    256,
    (res) => {
      console.log(`Result ${res}`);
    }
);

But I have the following error as result:

Got unknown argument class: int[]

A also try with java list<Integer> but it's also doesn't work.

Is it possible to pass a javascript list to a java function with a list argument ?

1 Answers
Related