public static IntPtr InvokeJavaProxyMethod(AndroidJavaProxy proxy, IntPtr jmethodName, IntPtr jargs) { int num = 0; if (jargs != IntPtr.Zero) { num = AndroidJNISafe.GetArrayLength(jargs); } AndroidJavaObject[] array = new AndroidJavaObject[num]; for (int i = 0; i < num; i++) { IntPtr objectArrayElement = AndroidJNISafe.GetObjectArrayElement(jargs, i); array[i] = ((!(objectArrayElement != IntPtr.Zero)) ? null : new AndroidJavaObject(objectArrayElement)); } IntPtr result; using (AndroidJavaObject androidJavaObject = proxy.Invoke(AndroidJNI.GetStringUTFChars(jmethodName), array)) { if (androidJavaObject == null) { result = IntPtr.Zero; } else { result = AndroidJNI.NewLocalRef(androidJavaObject.GetRawObject()); } } return(result); }
public static IntPtr InvokeJavaProxyMethod(AndroidJavaProxy proxy, IntPtr jmethodName, IntPtr jargs) { int arrayLength = 0; if (jargs != IntPtr.Zero) { arrayLength = AndroidJNISafe.GetArrayLength(jargs); } AndroidJavaObject[] javaArgs = new AndroidJavaObject[arrayLength]; for (int i = 0; i < arrayLength; i++) { IntPtr objectArrayElement = AndroidJNISafe.GetObjectArrayElement(jargs, i); javaArgs[i] = !(objectArrayElement != IntPtr.Zero) ? null : new AndroidJavaObject(objectArrayElement); } using (AndroidJavaObject obj2 = proxy.Invoke(AndroidJNI.GetStringUTFChars(jmethodName), javaArgs)) { if (obj2 == null) { return(IntPtr.Zero); } return(AndroidJNI.NewLocalRef(obj2.GetRawObject())); } }
public static IntPtr InvokeJavaProxyMethod(AndroidJavaProxy proxy, IntPtr jmethodName, IntPtr jargs) { int length = 0; if (jargs != IntPtr.Zero) { length = AndroidJNISafe.GetArrayLength(jargs); } AndroidJavaObject[] javaArgs = new AndroidJavaObject[length]; for (int index = 0; index < length; ++index) { IntPtr objectArrayElement = AndroidJNISafe.GetObjectArrayElement(jargs, index); javaArgs[index] = !(objectArrayElement != IntPtr.Zero) ? (AndroidJavaObject)null : new AndroidJavaObject(objectArrayElement); } using (AndroidJavaObject androidJavaObject = proxy.Invoke(AndroidJNI.GetStringUTFChars(jmethodName), javaArgs)) { if (androidJavaObject == null) { return(IntPtr.Zero); } return(AndroidJNI.NewLocalRef(androidJavaObject.GetRawObject())); } }
public static ArrayType ConvertFromJNIArray <ArrayType>(IntPtr array) { Type elementType = typeof(ArrayType).GetElementType(); if (AndroidReflection.IsPrimitive(elementType)) { if (elementType == typeof(int)) { return((ArrayType)(object)AndroidJNISafe.FromIntArray(array)); } if (elementType == typeof(bool)) { return((ArrayType)(object)AndroidJNISafe.FromBooleanArray(array)); } if (elementType == typeof(byte)) { return((ArrayType)(object)AndroidJNISafe.FromByteArray(array)); } if (elementType == typeof(short)) { return((ArrayType)(object)AndroidJNISafe.FromShortArray(array)); } if (elementType == typeof(long)) { return((ArrayType)(object)AndroidJNISafe.FromLongArray(array)); } if (elementType == typeof(float)) { return((ArrayType)(object)AndroidJNISafe.FromFloatArray(array)); } if (elementType == typeof(double)) { return((ArrayType)(object)AndroidJNISafe.FromDoubleArray(array)); } if (elementType == typeof(char)) { return((ArrayType)(object)AndroidJNISafe.FromCharArray(array)); } return(default(ArrayType)); } if (elementType == typeof(string)) { int arrayLength = AndroidJNISafe.GetArrayLength(array); string[] array2 = new string[arrayLength]; for (int i = 0; i < arrayLength; i++) { IntPtr objectArrayElement = AndroidJNI.GetObjectArrayElement(array, i); array2[i] = AndroidJNISafe.GetStringUTFChars(objectArrayElement); AndroidJNISafe.DeleteLocalRef(objectArrayElement); } return((ArrayType)(object)array2); } if (elementType == typeof(AndroidJavaObject)) { int arrayLength2 = AndroidJNISafe.GetArrayLength(array); AndroidJavaObject[] array3 = new AndroidJavaObject[arrayLength2]; for (int j = 0; j < arrayLength2; j++) { IntPtr objectArrayElement2 = AndroidJNI.GetObjectArrayElement(array, j); array3[j] = new AndroidJavaObject(objectArrayElement2); AndroidJNISafe.DeleteLocalRef(objectArrayElement2); } return((ArrayType)(object)array3); } throw new Exception("JNI: Unknown generic array type '" + elementType + "'"); }
public static ArrayType ConvertFromJNIArray <ArrayType>(IntPtr array) { System.Type elementType = typeof(ArrayType).GetElementType(); if (AndroidReflection.IsPrimitive(elementType)) { if (elementType == typeof(int)) { return((ArrayType)AndroidJNISafe.FromIntArray(array)); } if (elementType == typeof(bool)) { return((ArrayType)AndroidJNISafe.FromBooleanArray(array)); } if (elementType == typeof(byte)) { return((ArrayType)AndroidJNISafe.FromByteArray(array)); } if (elementType == typeof(short)) { return((ArrayType)AndroidJNISafe.FromShortArray(array)); } if (elementType == typeof(long)) { return((ArrayType)AndroidJNISafe.FromLongArray(array)); } if (elementType == typeof(float)) { return((ArrayType)AndroidJNISafe.FromFloatArray(array)); } if (elementType == typeof(double)) { return((ArrayType)AndroidJNISafe.FromDoubleArray(array)); } if (elementType == typeof(char)) { return((ArrayType)AndroidJNISafe.FromCharArray(array)); } return(default(ArrayType)); } if (elementType == typeof(string)) { int arrayLength = AndroidJNISafe.GetArrayLength(array); string[] strArray = new string[arrayLength]; for (int index = 0; index < arrayLength; ++index) { IntPtr objectArrayElement = AndroidJNI.GetObjectArrayElement(array, index); strArray[index] = AndroidJNISafe.GetStringUTFChars(objectArrayElement); AndroidJNISafe.DeleteLocalRef(objectArrayElement); } return((ArrayType)strArray); } if (elementType != typeof(AndroidJavaObject)) { throw new Exception("JNI: Unknown generic array type '" + (object)elementType + "'"); } int arrayLength1 = AndroidJNISafe.GetArrayLength(array); AndroidJavaObject[] androidJavaObjectArray = new AndroidJavaObject[arrayLength1]; for (int index = 0; index < arrayLength1; ++index) { IntPtr objectArrayElement = AndroidJNI.GetObjectArrayElement(array, index); androidJavaObjectArray[index] = new AndroidJavaObject(objectArrayElement); AndroidJNISafe.DeleteLocalRef(objectArrayElement); } return((ArrayType)androidJavaObjectArray); }