CreateJNIArgArray() public static method

public static CreateJNIArgArray ( Object args ) : UnityEngine.jvalue[]
args Object
return UnityEngine.jvalue[]
Exemplo n.º 1
0
        private void _AndroidJavaObject(string className, params object[] args)
        {
            this.DebugPrint("Creating AndroidJavaObject from " + className);
            bool flag = args == null;

            if (flag)
            {
                args = new object[1];
            }
            IntPtr jobject = AndroidJNISafe.FindClass(className.Replace('.', '/'));

            this.m_jclass = new GlobalJavaObjectRef(jobject);
            jvalue[] array = AndroidJNIHelper.CreateJNIArgArray(args);
            try
            {
                IntPtr constructorID = AndroidJNIHelper.GetConstructorID(this.m_jclass, args);
                IntPtr intPtr        = AndroidJNISafe.NewObject(this.m_jclass, constructorID, array);
                this.m_jobject = new GlobalJavaObjectRef(intPtr);
                AndroidJNISafe.DeleteLocalRef(intPtr);
            }
            finally
            {
                AndroidJNIHelper.DeleteJNIArgArray(args, array);
            }
        }
Exemplo n.º 2
0
        protected void _Call(string methodName, params object[] args)
        {
            if (args == null)
            {
                args = new object[1];
            }
            IntPtr methodID = AndroidJNIHelper.GetMethodID(this.m_jclass, methodName, args, false);

            jvalue[] jvalueArray = AndroidJNIHelper.CreateJNIArgArray(args);
            try
            {
                AndroidJNISafe.CallVoidMethod(this.m_jobject, methodID, jvalueArray);
            }
            finally
            {
                AndroidJNIHelper.DeleteJNIArgArray(args, jvalueArray);
            }
        }
Exemplo n.º 3
0
        protected void _CallStatic(string methodName, params object[] args)
        {
            if (args == null)
            {
                args = new object[1];
            }
            IntPtr methodID = AndroidJNIHelper.GetMethodID(m_jclass, methodName, args, isStatic: true);

            jvalue[] array = AndroidJNIHelper.CreateJNIArgArray(args);
            try
            {
                AndroidJNISafe.CallStaticVoidMethod(m_jclass, methodID, array);
            }
            finally
            {
                AndroidJNIHelper.DeleteJNIArgArray(args, array);
            }
        }
Exemplo n.º 4
0
 private void _AndroidJavaObject(string className, params object[] args)
 {
     this.DebugPrint("Creating AndroidJavaObject from " + className);
     if (args == null)
     {
         args = new object[1];
     }
     using (AndroidJavaObject androidJavaObject = AndroidJavaObject.FindClass(className))
     {
         this.m_jclass = AndroidJNI.NewGlobalRef(androidJavaObject.GetRawObject());
         jvalue[] jniArgArray = AndroidJNIHelper.CreateJNIArgArray(args);
         try
         {
             IntPtr localref = AndroidJNISafe.NewObject(this.m_jclass, AndroidJNIHelper.GetConstructorID(this.m_jclass, args), jniArgArray);
             this.m_jobject = AndroidJNI.NewGlobalRef(localref);
             AndroidJNISafe.DeleteLocalRef(localref);
         }
         finally
         {
             AndroidJNIHelper.DeleteJNIArgArray(args, jniArgArray);
         }
     }
 }
Exemplo n.º 5
0
        protected ReturnType _Call <ReturnType>(string methodName, params object[] args)
        {
            ReturnType local;

            if (args == null)
            {
                args = new object[1];
            }
            IntPtr methodID = AndroidJNIHelper.GetMethodID <ReturnType>(this.m_jclass, methodName, args, false);

            jvalue[] jvalueArray = AndroidJNIHelper.CreateJNIArgArray(args);
            try
            {
                if (AndroidReflection.IsPrimitive(typeof(ReturnType)))
                {
                    if (typeof(ReturnType) == typeof(int))
                    {
                        return((ReturnType)AndroidJNISafe.CallIntMethod(this.m_jobject, methodID, jvalueArray));
                    }
                    if (typeof(ReturnType) == typeof(bool))
                    {
                        return((ReturnType)AndroidJNISafe.CallBooleanMethod(this.m_jobject, methodID, jvalueArray));
                    }
                    if (typeof(ReturnType) == typeof(byte))
                    {
                        return((ReturnType)AndroidJNISafe.CallByteMethod(this.m_jobject, methodID, jvalueArray));
                    }
                    if (typeof(ReturnType) == typeof(short))
                    {
                        return((ReturnType)AndroidJNISafe.CallShortMethod(this.m_jobject, methodID, jvalueArray));
                    }
                    if (typeof(ReturnType) == typeof(long))
                    {
                        return((ReturnType)AndroidJNISafe.CallLongMethod(this.m_jobject, methodID, jvalueArray));
                    }
                    if (typeof(ReturnType) == typeof(float))
                    {
                        return((ReturnType)AndroidJNISafe.CallFloatMethod(this.m_jobject, methodID, jvalueArray));
                    }
                    if (typeof(ReturnType) == typeof(double))
                    {
                        return((ReturnType)AndroidJNISafe.CallDoubleMethod(this.m_jobject, methodID, jvalueArray));
                    }
                    if (typeof(ReturnType) == typeof(char))
                    {
                        return((ReturnType)AndroidJNISafe.CallCharMethod(this.m_jobject, methodID, jvalueArray));
                    }
                }
                else
                {
                    if (typeof(ReturnType) == typeof(string))
                    {
                        return((ReturnType)AndroidJNISafe.CallStringMethod(this.m_jobject, methodID, jvalueArray));
                    }
                    if (typeof(ReturnType) == typeof(AndroidJavaClass))
                    {
                        return((ReturnType)AndroidJavaClassDeleteLocalRef(AndroidJNISafe.CallObjectMethod(this.m_jobject, methodID, jvalueArray)));
                    }
                    if (typeof(ReturnType) == typeof(AndroidJavaObject))
                    {
                        return((ReturnType)AndroidJavaObjectDeleteLocalRef(AndroidJNISafe.CallObjectMethod(this.m_jobject, methodID, jvalueArray)));
                    }
                    if (!AndroidReflection.IsAssignableFrom(typeof(Array), typeof(ReturnType)))
                    {
                        throw new Exception("JNI: Unknown return type '" + typeof(ReturnType) + "'");
                    }
                    return(AndroidJNIHelper.ConvertFromJNIArray <ReturnType>(AndroidJNISafe.CallObjectMethod(this.m_jobject, methodID, jvalueArray)));
                }
                local = default(ReturnType);
            }
            finally
            {
                AndroidJNIHelper.DeleteJNIArgArray(args, jvalueArray);
            }
            return(local);
        }
Exemplo n.º 6
0
        protected ReturnType _CallStatic <ReturnType>(string methodName, params object[] args)
        {
            if (args == null)
            {
                args = new object[1];
            }
            IntPtr methodId = AndroidJNIHelper.GetMethodID <ReturnType>(this.m_jclass, methodName, args, true);

            jvalue[] jniArgArray = AndroidJNIHelper.CreateJNIArgArray(args);
            try
            {
                if (AndroidReflection.IsPrimitive(typeof(ReturnType)))
                {
                    if (typeof(ReturnType) == typeof(int))
                    {
                        return((ReturnType)(ValueType)AndroidJNISafe.CallStaticIntMethod(this.m_jclass, methodId, jniArgArray));
                    }
                    if (typeof(ReturnType) == typeof(bool))
                    {
                        return((ReturnType)(ValueType)AndroidJNISafe.CallStaticBooleanMethod(this.m_jclass, methodId, jniArgArray));
                    }
                    if (typeof(ReturnType) == typeof(byte))
                    {
                        return((ReturnType)(ValueType)AndroidJNISafe.CallStaticByteMethod(this.m_jclass, methodId, jniArgArray));
                    }
                    if (typeof(ReturnType) == typeof(short))
                    {
                        return((ReturnType)(ValueType)AndroidJNISafe.CallStaticShortMethod(this.m_jclass, methodId, jniArgArray));
                    }
                    if (typeof(ReturnType) == typeof(long))
                    {
                        return((ReturnType)(ValueType)AndroidJNISafe.CallStaticLongMethod(this.m_jclass, methodId, jniArgArray));
                    }
                    if (typeof(ReturnType) == typeof(float))
                    {
                        return((ReturnType)(ValueType)AndroidJNISafe.CallStaticFloatMethod(this.m_jclass, methodId, jniArgArray));
                    }
                    if (typeof(ReturnType) == typeof(double))
                    {
                        return((ReturnType)(ValueType)AndroidJNISafe.CallStaticDoubleMethod(this.m_jclass, methodId, jniArgArray));
                    }
                    if (typeof(ReturnType) == typeof(char))
                    {
                        return((ReturnType)(ValueType)AndroidJNISafe.CallStaticCharMethod(this.m_jclass, methodId, jniArgArray));
                    }
                    return(default(ReturnType));
                }
                if (typeof(ReturnType) == typeof(string))
                {
                    return((ReturnType)AndroidJNISafe.CallStaticStringMethod(this.m_jclass, methodId, jniArgArray));
                }
                if (typeof(ReturnType) == typeof(AndroidJavaClass))
                {
                    return((ReturnType)AndroidJavaObject.AndroidJavaClassDeleteLocalRef(AndroidJNISafe.CallStaticObjectMethod(this.m_jclass, methodId, jniArgArray)));
                }
                if (typeof(ReturnType) == typeof(AndroidJavaObject))
                {
                    return((ReturnType)AndroidJavaObject.AndroidJavaObjectDeleteLocalRef(AndroidJNISafe.CallStaticObjectMethod(this.m_jclass, methodId, jniArgArray)));
                }
                if (AndroidReflection.IsAssignableFrom(typeof(Array), typeof(ReturnType)))
                {
                    return(AndroidJNIHelper.ConvertFromJNIArray <ReturnType>(AndroidJNISafe.CallStaticObjectMethod(this.m_jclass, methodId, jniArgArray)));
                }
                throw new Exception("JNI: Unknown return type '" + (object)typeof(ReturnType) + "'");
            }
            finally
            {
                AndroidJNIHelper.DeleteJNIArgArray(args, jniArgArray);
            }
        }
        protected ReturnType _CallStatic <ReturnType>(string methodName, params object[] args)
        {
            if (args == null)
            {
                args = new object[1];
            }
            IntPtr methodID = AndroidJNIHelper.GetMethodID <ReturnType>(this.m_jclass, methodName, args, true);

            jvalue[]   array = AndroidJNIHelper.CreateJNIArgArray(args);
            ReturnType result;

            try
            {
                if (AndroidReflection.IsPrimitive(typeof(ReturnType)))
                {
                    if (typeof(ReturnType) == typeof(int))
                    {
                        result = (ReturnType)((object)AndroidJNISafe.CallStaticIntMethod(this.m_jclass, methodID, array));
                    }
                    else if (typeof(ReturnType) == typeof(bool))
                    {
                        result = (ReturnType)((object)AndroidJNISafe.CallStaticBooleanMethod(this.m_jclass, methodID, array));
                    }
                    else if (typeof(ReturnType) == typeof(byte))
                    {
                        result = (ReturnType)((object)AndroidJNISafe.CallStaticByteMethod(this.m_jclass, methodID, array));
                    }
                    else if (typeof(ReturnType) == typeof(short))
                    {
                        result = (ReturnType)((object)AndroidJNISafe.CallStaticShortMethod(this.m_jclass, methodID, array));
                    }
                    else if (typeof(ReturnType) == typeof(long))
                    {
                        result = (ReturnType)((object)AndroidJNISafe.CallStaticLongMethod(this.m_jclass, methodID, array));
                    }
                    else if (typeof(ReturnType) == typeof(float))
                    {
                        result = (ReturnType)((object)AndroidJNISafe.CallStaticFloatMethod(this.m_jclass, methodID, array));
                    }
                    else if (typeof(ReturnType) == typeof(double))
                    {
                        result = (ReturnType)((object)AndroidJNISafe.CallStaticDoubleMethod(this.m_jclass, methodID, array));
                    }
                    else if (typeof(ReturnType) == typeof(char))
                    {
                        result = (ReturnType)((object)AndroidJNISafe.CallStaticCharMethod(this.m_jclass, methodID, array));
                    }
                    else
                    {
                        result = default(ReturnType);
                    }
                }
                else if (typeof(ReturnType) == typeof(string))
                {
                    result = (ReturnType)((object)AndroidJNISafe.CallStaticStringMethod(this.m_jclass, methodID, array));
                }
                else if (typeof(ReturnType) == typeof(AndroidJavaClass))
                {
                    IntPtr intPtr = AndroidJNISafe.CallStaticObjectMethod(this.m_jclass, methodID, array);
                    result = ((!(intPtr == IntPtr.Zero)) ? ((ReturnType)((object)AndroidJavaObject.AndroidJavaClassDeleteLocalRef(intPtr))) : default(ReturnType));
                }
                else if (typeof(ReturnType) == typeof(AndroidJavaObject))
                {
                    IntPtr intPtr2 = AndroidJNISafe.CallStaticObjectMethod(this.m_jclass, methodID, array);
                    result = ((!(intPtr2 == IntPtr.Zero)) ? ((ReturnType)((object)AndroidJavaObject.AndroidJavaObjectDeleteLocalRef(intPtr2))) : default(ReturnType));
                }
                else
                {
                    if (!AndroidReflection.IsAssignableFrom(typeof(Array), typeof(ReturnType)))
                    {
                        throw new Exception("JNI: Unknown return type '" + typeof(ReturnType) + "'");
                    }
                    IntPtr intPtr3 = AndroidJNISafe.CallStaticObjectMethod(this.m_jclass, methodID, array);
                    result = ((!(intPtr3 == IntPtr.Zero)) ? ((ReturnType)((object)AndroidJNIHelper.ConvertFromJNIArray <ReturnType>(intPtr3))) : default(ReturnType));
                }
            }
            finally
            {
                AndroidJNIHelper.DeleteJNIArgArray(args, array);
            }
            return(result);
        }
Exemplo n.º 8
0
        protected ReturnType _CallStatic <ReturnType>(string methodName, params object[] args)
        {
            bool flag = args == null;

            if (flag)
            {
                args = new object[1];
            }
            IntPtr methodID = AndroidJNIHelper.GetMethodID <ReturnType>(this.m_jclass, methodName, args, true);

            jvalue[]   array = AndroidJNIHelper.CreateJNIArgArray(args);
            ReturnType result;

            try
            {
                bool flag2 = AndroidReflection.IsPrimitive(typeof(ReturnType));
                if (flag2)
                {
                    bool flag3 = typeof(ReturnType) == typeof(int);
                    if (flag3)
                    {
                        result = (ReturnType)((object)AndroidJNISafe.CallStaticIntMethod(this.m_jclass, methodID, array));
                    }
                    else
                    {
                        bool flag4 = typeof(ReturnType) == typeof(bool);
                        if (flag4)
                        {
                            result = (ReturnType)((object)AndroidJNISafe.CallStaticBooleanMethod(this.m_jclass, methodID, array));
                        }
                        else
                        {
                            bool flag5 = typeof(ReturnType) == typeof(byte);
                            if (flag5)
                            {
                                Debug.LogWarning("Return type <Byte> for Java method call is obsolete, use return type <SByte> instead");
                                result = (ReturnType)((object)((byte)AndroidJNISafe.CallStaticSByteMethod(this.m_jclass, methodID, array)));
                            }
                            else
                            {
                                bool flag6 = typeof(ReturnType) == typeof(sbyte);
                                if (flag6)
                                {
                                    result = (ReturnType)((object)AndroidJNISafe.CallStaticSByteMethod(this.m_jclass, methodID, array));
                                }
                                else
                                {
                                    bool flag7 = typeof(ReturnType) == typeof(short);
                                    if (flag7)
                                    {
                                        result = (ReturnType)((object)AndroidJNISafe.CallStaticShortMethod(this.m_jclass, methodID, array));
                                    }
                                    else
                                    {
                                        bool flag8 = typeof(ReturnType) == typeof(long);
                                        if (flag8)
                                        {
                                            result = (ReturnType)((object)AndroidJNISafe.CallStaticLongMethod(this.m_jclass, methodID, array));
                                        }
                                        else
                                        {
                                            bool flag9 = typeof(ReturnType) == typeof(float);
                                            if (flag9)
                                            {
                                                result = (ReturnType)((object)AndroidJNISafe.CallStaticFloatMethod(this.m_jclass, methodID, array));
                                            }
                                            else
                                            {
                                                bool flag10 = typeof(ReturnType) == typeof(double);
                                                if (flag10)
                                                {
                                                    result = (ReturnType)((object)AndroidJNISafe.CallStaticDoubleMethod(this.m_jclass, methodID, array));
                                                }
                                                else
                                                {
                                                    bool flag11 = typeof(ReturnType) == typeof(char);
                                                    if (flag11)
                                                    {
                                                        result = (ReturnType)((object)AndroidJNISafe.CallStaticCharMethod(this.m_jclass, methodID, array));
                                                    }
                                                    else
                                                    {
                                                        result = default(ReturnType);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    bool flag12 = typeof(ReturnType) == typeof(string);
                    if (flag12)
                    {
                        result = (ReturnType)((object)AndroidJNISafe.CallStaticStringMethod(this.m_jclass, methodID, array));
                    }
                    else
                    {
                        bool flag13 = typeof(ReturnType) == typeof(AndroidJavaClass);
                        if (flag13)
                        {
                            IntPtr intPtr = AndroidJNISafe.CallStaticObjectMethod(this.m_jclass, methodID, array);
                            result = ((intPtr == IntPtr.Zero) ? default(ReturnType) : ((ReturnType)((object)AndroidJavaObject.AndroidJavaClassDeleteLocalRef(intPtr))));
                        }
                        else
                        {
                            bool flag14 = typeof(ReturnType) == typeof(AndroidJavaObject);
                            if (flag14)
                            {
                                IntPtr intPtr2 = AndroidJNISafe.CallStaticObjectMethod(this.m_jclass, methodID, array);
                                result = ((intPtr2 == IntPtr.Zero) ? default(ReturnType) : ((ReturnType)((object)AndroidJavaObject.AndroidJavaObjectDeleteLocalRef(intPtr2))));
                            }
                            else
                            {
                                bool flag15 = AndroidReflection.IsAssignableFrom(typeof(Array), typeof(ReturnType));
                                if (!flag15)
                                {
                                    string arg_408_0 = "JNI: Unknown return type '";
                                    Type   expr_3F7  = typeof(ReturnType);
                                    throw new Exception(arg_408_0 + ((expr_3F7 != null) ? expr_3F7.ToString() : null) + "'");
                                }
                                IntPtr intPtr3 = AndroidJNISafe.CallStaticObjectMethod(this.m_jclass, methodID, array);
                                result = ((intPtr3 == IntPtr.Zero) ? default(ReturnType) : ((ReturnType)((object)AndroidJNIHelper.ConvertFromJNIArray <ReturnType>(intPtr3))));
                            }
                        }
                    }
                }
            }
            finally
            {
                AndroidJNIHelper.DeleteJNIArgArray(args, array);
            }
            return(result);
        }