Pierre Stone
Pierre Stone

Reputation: 11

Android: Sharing data between native code (C) and application (java)

I have a native app running on Android 5.0, an audio effect actually, that get launched on camcorder recording usecase (for instance). I have an application that needs to retrieve some data from it, 3 integers exaclty, that changes constantly.

How can a share these data from my native process with my application?

What are the options?

I had a look to ashmem but cannot find an example for my case, I tried to write my data to a file and read them with from jni, but when I launch this read function, I dont see any trace of the native function (only the jni itself) and get constant random numbers... (but no crash)

Thanks, Pierre

Upvotes: 1

Views: 791

Answers (1)

EntangledLoops
EntangledLoops

Reputation: 2136

Have a look at the JNI documentation. There are many functions available for this of the form:

 env->GetShortArrayRegion(currentDim, 0, size, buffer[i]);

You can also pass a long pointer between your Java & C app that points to a native C/C++ structure.

Upvotes: 1

Related Questions