函数指针。
这应该使用 Marshal.GetFunctionPointerForDelegate 获取,委托应该引用一个用 MonoPInvokeCallback 属性注释且具有以下签名的方法:static ReturnType MyMethod(IntPtr jniEnv, IntPtr objectOrClass, ...);
// Delegate difinition delegate void JavaToCs(IntPtr jniEnv, IntPtr klass, int x);
// Method definition [MonoPInvokeCallback(typeof(JavaToCs))] static void CsMethod(IntPtr jniEnv, IntPtr klass, int x) { Debug.Log("From Java: " + x); }
// Array to be passed to AndroidJNI.RegisterNative var methods = new JNINativeMethod[] { new JNINativeMethod { name = "csMethod", signature = "(I)V", fnPtr = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(new JavaToCs(CsMethod)), } };
// Register method for Java class AndroidJNI.RegisterNatives(clazz, methods);