public static void CallStaticSafe(this AndroidJavaObject ajo, string methodName, params object[] args) { try { ajo.CallStatic(methodName, args); } catch (Exception e) { GetSocialDebugLogger.Ex(e, string.Format("Failed to call {0} on {1}", methodName, ajo.GetClassName())); } }
public static void CallSafe(this AndroidJavaObject ajo, string methodName, params object[] args) { try { ajo.Call(methodName, args); } catch (Exception exception) { GetSocialDebugLogger.Ex(exception, string.Format("Failed to call {0} because of: {1}", methodName, exception.Message)); } }
private static void HandleAndroidJavaObjectCallException <T>(AndroidJavaObject ajo, string methodName, Exception exception) { // If we call method that return null from Java an exception will be thrown. So we have to ignore most part of them. // Related Unity issue: https://issuetracker.unity3d.com/issues/androidjavaobject-dot-call-throws-exception-instead-of-returning-null-pointer // Fixed in Unity 5.6.0 var isExceptionCausedByNullObjectReturnedFromJava = typeof(T) == typeof(AndroidJavaObject) && exception.Message.Contains("AndroidJavaObject with null ptr"); if (!isExceptionCausedByNullObjectReturnedFromJava) { GetSocialDebugLogger.Ex(exception, string.Format("Failed to call {0} on {1}", methodName, ajo)); } }