public T InvokeCall <T>(string name, string sig, params object[] args) { T local; Type type = typeof(T); IntPtr methodID = AndroidJNI.GetMethodID(this.RawClass, name, sig); if (methodID == IntPtr.Zero) { Debug.LogError("Cannot get method for " + name); throw new Exception("Cannot get method for " + name); } jvalue[] jvalueArray = ConstructArgArray(args); try { if (type == typeof(bool)) { return((T)AndroidJNI.CallBooleanMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(string)) { return((T)AndroidJNI.CallStringMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(int)) { return((T)AndroidJNI.CallIntMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(float)) { return((T)AndroidJNI.CallFloatMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(double)) { return((T)AndroidJNI.CallDoubleMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(byte)) { return((T)AndroidJNI.CallByteMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(char)) { return((T)AndroidJNI.CallCharMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(long)) { return((T)AndroidJNI.CallLongMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(short)) { return((T)AndroidJNI.CallShortMethod(this.raw, methodID, jvalueArray)); } local = this.InvokeObjectCall <T>(name, sig, args); } finally { AndroidJNIHelper.DeleteJNIArgArray(args, jvalueArray); } return(local); }
public static long CallLongMethod(IntPtr obj, IntPtr methodId, jvalue[] args) { try { return(AndroidJNI.CallLongMethod(obj, methodId, args)); } finally { CheckException(); } }
public T InvokeCall <T>(string name, string sig, params object[] args) { System.Type type = typeof(T); IntPtr objectClass = AndroidJNI.GetObjectClass(this.raw); IntPtr methodID = AndroidJNI.GetMethodID(objectClass, name, sig); jvalue[] jvalueArray = ConstructArgArray(args); if (objectClass == IntPtr.Zero) { Debug.LogError("Cannot get rawClass object!"); throw new Exception("Cannot get rawClass object"); } if (methodID == IntPtr.Zero) { Debug.LogError("Cannot get method for " + name); throw new Exception("Cannot get method for " + name); } if (type == typeof(bool)) { return((T)AndroidJNI.CallBooleanMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(string)) { return((T)AndroidJNI.CallStringMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(int)) { return((T)AndroidJNI.CallIntMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(float)) { return((T)AndroidJNI.CallFloatMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(double)) { return((T)AndroidJNI.CallDoubleMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(byte)) { return((T)AndroidJNI.CallByteMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(char)) { return((T)AndroidJNI.CallCharMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(long)) { return((T)AndroidJNI.CallLongMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(short)) { return((T)AndroidJNI.CallShortMethod(this.raw, methodID, jvalueArray)); } return(this.InvokeObjectCall <T>(name, sig, args)); }
public T InvokeCall <T>(string name, string sig, params object[] args) { Type t = typeof(T); IntPtr method = AndroidJNI.GetMethodID(RawClass, name, sig); jvalue[] jArgs = ConstructArgArray(args); if (method == IntPtr.Zero) { Debug.LogError("Cannot get method for " + name); throw new Exception("Cannot get method for " + name); } if (t == typeof(bool)) { return((T)(object)AndroidJNI.CallBooleanMethod(raw, method, jArgs)); } else if (t == typeof(string)) { return((T)(object)AndroidJNI.CallStringMethod(raw, method, jArgs)); } else if (t == typeof(int)) { return((T)(object)AndroidJNI.CallIntMethod(raw, method, jArgs)); } else if (t == typeof(float)) { return((T)(object)AndroidJNI.CallFloatMethod(raw, method, jArgs)); } else if (t == typeof(double)) { return((T)(object)AndroidJNI.CallDoubleMethod(raw, method, jArgs)); } else if (t == typeof(byte)) { return((T)(object)AndroidJNI.CallByteMethod(raw, method, jArgs)); } else if (t == typeof(char)) { return((T)(object)AndroidJNI.CallCharMethod(raw, method, jArgs)); } else if (t == typeof(long)) { return((T)(object)AndroidJNI.CallLongMethod(raw, method, jArgs)); } else if (t == typeof(short)) { return((T)(object)AndroidJNI.CallShortMethod(raw, method, jArgs)); } else { return(InvokeObjectCall <T>(name, sig, args)); } }
protected override void initParamsFromAndroidJavaObject(AndroidJavaObject instance) { base.initParamsFromAndroidJavaObject(instance); this.progressType = AndroidJNI.CallStringMethod(instance.GetRawObject(), AndroidJNIHelper.GetMethodID(instance.GetRawClass(), "getProgressType", "()Ljava/lang/String"), new jvalue[0] { }); this.videoLength = AndroidJNI.CallStringMethod(instance.GetRawObject(), AndroidJNIHelper.GetMethodID(instance.GetRawClass(), "getVideoLength", "()Ljava/lang/String"), new jvalue[0] { }); this.progressColor = AndroidJNI.CallStringMethod(instance.GetRawObject(), AndroidJNIHelper.GetMethodID(instance.GetRawClass(), "getProgressColor", "()Ljava/lang/String"), new jvalue[0] { }); this.delay = AndroidJNI.CallLongMethod(instance.GetRawObject(), AndroidJNIHelper.GetMethodID(instance.GetRawClass(), "getCloseDelay", "()J"), new jvalue[0] { }); this.showClose = AndroidJNI.CallBooleanMethod(instance.GetRawObject(), AndroidJNIHelper.GetMethodID(instance.GetRawClass(), "isShowClose", "()Z"), new jvalue[0] { }); }
public T InvokeCall <T>(string name, string sig, params object[] args) { Type t = typeof(T); IntPtr rawClass = AndroidJNI.GetObjectClass(raw); IntPtr method = AndroidJNI.GetMethodID(rawClass, name, sig); jvalue[] jArgs = ConstructArgArray(args); if (t == typeof(bool)) { return((T)(object)AndroidJNI.CallBooleanMethod(raw, method, jArgs)); } else if (t == typeof(string)) { return((T)(object)AndroidJNI.CallStringMethod(raw, method, jArgs)); } else if (t == typeof(int)) { return((T)(object)AndroidJNI.CallIntMethod(raw, method, jArgs)); } else if (t == typeof(float)) { return((T)(object)AndroidJNI.CallFloatMethod(raw, method, jArgs)); } else if (t == typeof(double)) { return((T)(object)AndroidJNI.CallDoubleMethod(raw, method, jArgs)); } else if (t == typeof(byte)) { return((T)(object)AndroidJNI.CallByteMethod(raw, method, jArgs)); } else if (t == typeof(char)) { return((T)(object)AndroidJNI.CallCharMethod(raw, method, jArgs)); } else if (t == typeof(long)) { return((T)(object)AndroidJNI.CallLongMethod(raw, method, jArgs)); } else if (t == typeof(short)) { return((T)(object)AndroidJNI.CallShortMethod(raw, method, jArgs)); } else { return(InvokeObjectCall <T>(name, sig, args)); } }
public override float GetCurrentTimeMs() { float result = 0.0f; if (m_Video != null) { if (m_Method_GetCurrentTimeMs != System.IntPtr.Zero) { result = AndroidJNI.CallLongMethod(m_Video.GetRawObject(), m_Method_GetCurrentTimeMs, m_Value0); } else { result = (float)m_Video.Call <long>("GetCurrentTimeMs"); } } return(result); }
public T InvokeCall <T>(string name, string sig, params object[] args) { Type type = typeof(T); IntPtr methodId = AndroidJNI.GetMethodID(AndroidJNI.GetObjectClass(this.raw), name, sig); jvalue[] jvalueArray = JavaObjWrapper.ConstructArgArray(args); if ((object)type == (object)typeof(bool)) { return((T)(ValueType)AndroidJNI.CallBooleanMethod(this.raw, methodId, jvalueArray)); } if ((object)type == (object)typeof(string)) { return((T)AndroidJNI.CallStringMethod(this.raw, methodId, jvalueArray)); } if ((object)type == (object)typeof(int)) { return((T)(ValueType)AndroidJNI.CallIntMethod(this.raw, methodId, jvalueArray)); } if ((object)type == (object)typeof(float)) { return((T)(ValueType)AndroidJNI.CallFloatMethod(this.raw, methodId, jvalueArray)); } if ((object)type == (object)typeof(double)) { return((T)(ValueType)AndroidJNI.CallDoubleMethod(this.raw, methodId, jvalueArray)); } if ((object)type == (object)typeof(byte)) { return((T)(ValueType)AndroidJNI.CallByteMethod(this.raw, methodId, jvalueArray)); } if ((object)type == (object)typeof(char)) { return((T)(ValueType)AndroidJNI.CallCharMethod(this.raw, methodId, jvalueArray)); } if ((object)type == (object)typeof(long)) { return((T)(ValueType)AndroidJNI.CallLongMethod(this.raw, methodId, jvalueArray)); } if ((object)type == (object)typeof(short)) { return((T)(ValueType)AndroidJNI.CallShortMethod(this.raw, methodId, jvalueArray)); } return(this.InvokeObjectCall <T>(name, sig, args)); }
public static ulong URLClientMovePendingResponseContent(uint connectionID, byte[] dst, ulong dstLength) { ulong length; #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_IPHONE GCHandle pinnedArray = GCHandle.Alloc(dst, GCHandleType.Pinned); IntPtr ptrDst = pinnedArray.AddrOfPinnedObject(); length = _URLClientMovePendingResponseContent(connectionID, ptrDst, dstLength); pinnedArray.Free(); #elif UNITY_ANDROID IntPtr rawClass = UnityURLClientBindingInstance.GetRawClass(); IntPtr rawObject = UnityURLClientBindingInstance.GetRawObject(); IntPtr methodPtr = AndroidJNI.GetMethodID(rawClass, "movePendingResponseContent", "(I[BJ)J"); IntPtr v2 = AndroidJNI.ToByteArray(dst); jvalue j1 = new jvalue(); j1.i = (int)connectionID; jvalue j2 = new jvalue(); j2.l = v2; jvalue j3 = new jvalue(); j3.j = (long)dstLength; length = (ulong)AndroidJNI.CallLongMethod(rawObject, methodPtr, new jvalue[] { j1, j2, j3 }); if (dst != null) { byte[] resultDst = AndroidJNI.FromByteArray(v2); for (ulong n = 0; n < length; ++n) { dst[n] = resultDst[n]; } } AndroidJNI.DeleteLocalRef(v2); #endif return(length); }
protected static void GetFileInformation(String name, ref long length, ref IntPtr pDataUnManaged) { #if UNITY_ANDROID long start; Int32 fd; IntPtr cls_Activity = (IntPtr)AndroidJNI.FindClass("com/unity3d/player/UnityPlayer"); IntPtr fid_Activity = AndroidJNI.GetStaticFieldID(cls_Activity, "currentActivity", "Landroid/app/Activity;"); IntPtr obj_Activity = AndroidJNI.GetStaticObjectField(cls_Activity, fid_Activity); IntPtr obj_cls = AndroidJNI.GetObjectClass(obj_Activity); IntPtr asset_func = AndroidJNI.GetMethodID(obj_cls, "getAssets", "()Landroid/content/res/AssetManager;"); IntPtr assetManager = AndroidJNI.CallObjectMethod(obj_Activity, asset_func, new jvalue[2]); IntPtr assetManagerClass = AndroidJNI.GetObjectClass(assetManager); IntPtr openFd = AndroidJNI.GetMethodID(assetManagerClass, "openFd", "(Ljava/lang/String;)Landroid/content/res/AssetFileDescriptor;"); jvalue[] param_array2 = new jvalue[2]; jvalue param = new jvalue(); param.l = AndroidJNI.NewStringUTF(name); param_array2[0] = param; IntPtr jfd; try { jfd = AndroidJNI.CallObjectMethod(assetManager, openFd, param_array2); IntPtr assetFdClass = AndroidJNI.GetObjectClass(jfd); IntPtr getParcelFd = AndroidJNI.GetMethodID(assetFdClass, "getParcelFileDescriptor", "()Landroid/os/ParcelFileDescriptor;"); IntPtr getStartOffset = AndroidJNI.GetMethodID(assetFdClass, "getStartOffset", "()J"); IntPtr getLength = AndroidJNI.GetMethodID(assetFdClass, "getLength", "()J"); start = AndroidJNI.CallLongMethod(jfd, getStartOffset, new jvalue[2]); length = AndroidJNI.CallLongMethod(jfd, getLength, new jvalue[2]); IntPtr fileInputStreamId = AndroidJNI.GetMethodID(assetFdClass, "createInputStream", "()Ljava/io/FileInputStream;"); IntPtr fileInputStream = AndroidJNI.CallObjectMethod(jfd, fileInputStreamId, new jvalue[2]); IntPtr fileInputStreamClass = AndroidJNI.GetObjectClass(fileInputStream); // Method signatures:newbytear B: byte, Z: boolean IntPtr read = AndroidJNI.GetMethodID(fileInputStreamClass, "read", "([BII)I"); jvalue[] param_array = new jvalue[3]; jvalue param1 = new jvalue(); IntPtr pData = AndroidJNI.NewByteArray((int)(length)); param1.l = pData; jvalue param2 = new jvalue(); param2.i = 0; jvalue param3 = new jvalue(); param3.i = (int)(length); param_array[0] = param1; param_array[1] = param2; param_array[2] = param3; int numBytesRead = AndroidJNI.CallIntMethod(fileInputStream, read, param_array); UnityEngine.Debug.Log("Bytes Read = " + numBytesRead); Byte[] pDataManaged = AndroidJNI.FromByteArray(pData); pDataUnManaged = Marshal.AllocCoTaskMem((int)length); Marshal.Copy(pDataManaged, 0, pDataUnManaged, (int)length); jfd = AndroidJNI.CallObjectMethod(jfd, getParcelFd, new jvalue[2]); IntPtr parcelFdClass = AndroidJNI.GetObjectClass(jfd); jvalue[] param_array3 = new jvalue[2]; IntPtr getFd = AndroidJNI.GetMethodID(parcelFdClass, "getFileDescriptor", "()Ljava/io/FileDescriptor;"); jfd = AndroidJNI.CallObjectMethod(jfd, getFd, param_array3); IntPtr fdClass = AndroidJNI.GetObjectClass(jfd); IntPtr descriptor = AndroidJNI.GetFieldID(fdClass, "descriptor", "I"); fd = AndroidJNI.GetIntField(jfd, descriptor); } catch (IOException ex) { UnityEngine.Debug.Log("IO Exception: Failed to load swf file"); } #endif return; }