android - Get native JavaVM and JNIEnv handles in Xamarin c# project -


i have android native library use via p/invoke in xamarin c# project.

initialization call library expects following parameters:

javavm * javavm jnienv * jnienv void *   activityobject 

on sample ndk project library, initialisation set (directly @ beginning of android_main entry point):

javavm = app->activity->vm; activityobject = app->activity->clazz; 

jnienv set as:

javavm->attachcurrentthread( javavm, &jnienv, null ); 

and initialize dll function called parameters.

now initialize pointers c# xamarin project.

app->activity point following anativeactivity need equivalent handles initialize in c# activity.

so considering , activity object "act", need perform following:

public unsafe class mainactivity : activity {     [system.runtime.interopservices.dllimport("ndklib.so")]     public static int initlibrary(intptr javavm, intptr jnienv, intptr activityobject);      protected override void oncreate(bundle bundle)     {          intptr javavm = ???          intptr jnienv = ???          intptr activityobject = ????           initlibrary(javavm, jnienv, activityobject);     }  } 

1/ expect activity object as:

intptr activityobject = act.class.handle; 

2/i can't find how retrieve javavm * handle anywhere.

the close thing can find in jnienv :

 static intptr java_vm; 

which private field not accessible anywhere (i can access via reflection only), correct? (and if so, there's way handle without resorting reflection tricks?).

3/ once javavm handle, still can't see equivalent call attachcurrentthread within c# xamarin api.

is possible perform following, , current handle (which imply attached) ? or there way so?

intptr jnienv = jnienv.handle; 

thanks


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -