コード例 #1
0
        protected void _Call(string methodName, params object[] args)
        {
            if (args == null)
            {
                args = new object[1];
            }
            string signature = AndroidJNIHelper.GetSignature(args);

            Debug.Warning("Call<void>" + methodName + signature + args);
            IntPtr cachedMethodID = AndroidJNIHelper.GetMethodID(this.m_jclass, methodName, args, false);

            jvalue[] args2 = AndroidJNIHelper.CreateJNIArgArray(args);
            AndroidJNI.CallVoidMethod(this.m_jobject, cachedMethodID, args2);
        }
コード例 #2
0
        protected ReturnType _Call <ReturnType>(string methodName, params object[] args)
        {
            if (args == null)
            {
                args = new object[1];
            }
            string signature = AndroidJNIHelper.GetSignature <ReturnType>(args);

            Debug.Warning("Call<" + typeof(ReturnType).ToString() + ">" + methodName + signature + args);
            IntPtr cachedMethodID = AndroidJNIHelper.GetMethodID <ReturnType> (this.m_jclass, methodName, args, false);

            jvalue[] args2 = AndroidJNIHelper.CreateJNIArgArray(args);
            if (typeof(ReturnType).IsPrimitive)
            {
                if (typeof(ReturnType) == typeof(int))
                {
                    object rt = AndroidJNI.CallIntMethod(this.m_jobject, cachedMethodID, args2);
                    return((ReturnType)rt);
                }
                if (typeof(ReturnType) == typeof(bool))
                {
                    object rt = AndroidJNI.CallBooleanMethod(this.m_jobject, cachedMethodID, args2);
                    return((ReturnType)rt);
                }
                if (typeof(ReturnType) == typeof(byte))
                {
                    object rt = AndroidJNI.CallByteMethod(this.m_jobject, cachedMethodID, args2);
                    return((ReturnType)rt);
                }
                if (typeof(ReturnType) == typeof(short))
                {
                    object rt = AndroidJNI.CallShortMethod(this.m_jobject, cachedMethodID, args2);
                    return((ReturnType)rt);
                }
                if (typeof(ReturnType) == typeof(long))
                {
                    object rt = AndroidJNI.CallLongMethod(this.m_jobject, cachedMethodID, args2);
                    return((ReturnType)rt);
                }
                if (typeof(ReturnType) == typeof(float))
                {
                    object rt = AndroidJNI.CallFloatMethod(this.m_jobject, cachedMethodID, args2);
                    return((ReturnType)rt);
                }
                if (typeof(ReturnType) == typeof(double))
                {
                    object rt = AndroidJNI.CallDoubleMethod(this.m_jobject, cachedMethodID, args2);
                    return((ReturnType)rt);
                }
                if (typeof(ReturnType) == typeof(char))
                {
                    object rt = AndroidJNI.CallCharMethod(this.m_jobject, cachedMethodID, args2);
                    return((ReturnType)rt);
                }
            }
            else
            {
                if (typeof(ReturnType) == typeof(string))
                {
                    object rt = AndroidJNI.CallStringMethod(this.m_jobject, cachedMethodID, args2);
                    return((ReturnType)rt);
                }
                if (typeof(ReturnType) == typeof(AndroidJavaObject))
                {
                    IntPtr jobject = AndroidJNI.CallObjectMethod(this.m_jobject, cachedMethodID, args2);
                    object rt      = new AndroidJavaObject(jobject);
                    return((ReturnType)rt);
                }
//                 if (typeof(Array).IsAssignableFrom(typeof(ReturnType)))
//                 {
//                     IntPtr array = AndroidJNI.CallObjectMethod(this.m_jobject, cachedMethodID, args2);
//                     return (ReturnType)AndroidJNIHelper.ConvertFromJNIArray<ReturnType>(array);
//                 }
                Debug.Warning("JNI: Unknown return type '" + typeof(ReturnType) + "'");
            }
            return(default(ReturnType));
        }