/// <summary> /// Calls a class static method. /// /// <para> /// NOTE: be sure you passing correct type (it shoud be the primitive or the type derived from <see cref="JavaObject"/>)! /// </para> /// /// </summary> /// <returns>The invoke call.</returns> /// <param name="type">Type.</param> /// <param name="name">Method name.</param> /// <param name="args">Arguments.</param> /// <typeparam name="TReturnType"></typeparam> public static TReturnType CallStatic <TReturnType>(string type, string name, params object[] args) { Type t = typeof(TReturnType); string sig = GetSignature <TReturnType>(args); IntPtr rawClass = FindClass(type); IntPtr method = AndroidJNIHelper.GetMethodID(rawClass, name, sig, true); jvalue[] jArgs = ConstructArgArray(args); try { if (AndroidReflection.IsPrimitive(t)) { if (t == typeof(bool)) { return((TReturnType)(object)JNISafe.CallStaticBooleanMethod(rawClass, method, jArgs)); } if (t == typeof(int)) { return((TReturnType)(object)JNISafe.CallStaticIntMethod(rawClass, method, jArgs)); } if (t == typeof(float)) { return((TReturnType)(object)JNISafe.CallStaticFloatMethod(rawClass, method, jArgs)); } if (t == typeof(double)) { return((TReturnType)(object)JNISafe.CallStaticDoubleMethod(rawClass, method, jArgs)); } if (t == typeof(byte)) { return((TReturnType)(object)JNISafe.CallStaticByteMethod(rawClass, method, jArgs)); } if (t == typeof(char)) { return((TReturnType)(object)JNISafe.CallStaticCharMethod(rawClass, method, jArgs)); } if (t == typeof(long)) { return((TReturnType)(object)JNISafe.CallStaticLongMethod(rawClass, method, jArgs)); } if (t == typeof(short)) { return((TReturnType)(object)JNISafe.CallStaticShortMethod(rawClass, method, jArgs)); } } if (t == typeof(string)) { return((TReturnType)(object)JNISafe.CallStaticStringMethod(rawClass, method, jArgs)); } if (t.IsSubclassOf(typeof(JavaObject))) { IntPtr val = JNISafe.CallStaticObjectMethod(rawClass, method, jArgs); if (val == IntPtr.Zero) { return(default(TReturnType)); } ConstructorInfo c = t.GetConstructor(new[] { val.GetType() }); if (c != null) { return((TReturnType)c.Invoke(new object[] { val })); } else { DebugPrint("Can't instantiate class, probably no constructor with IntPtr arg"); } } } finally { AndroidJNIHelper.DeleteJNIArgArray(args, jArgs); } return(default(TReturnType)); }