8 const string TAG =
"SafeJNI";
17 public static bool SafeCallStatic(
this AndroidJavaObject obj,
string methodName, params
object[] args)
26 if (args ==
null || args.Length == 0)
27 obj.CallStatic(methodName);
29 obj.CallStatic(methodName, args);
32 catch (AndroidJavaException e)
34 Debug.unityLogger.Log(LogType.Exception,
TAG,
"JNI Exception: " + e);
39 Debug.unityLogger.Log(LogType.Exception,
TAG,
"Unexpected Exception: " + ex);
61 if (args ==
null || args.Length == 0)
62 return obj.CallStatic<ReturnType>(methodName);
64 return obj.CallStatic<ReturnType>(methodName, args);
66 catch (AndroidJavaException e)
68 Debug.unityLogger.Log(LogType.Exception,
TAG,
"JNI Exception: " + e);
73 Debug.unityLogger.Log(LogType.Exception,
TAG,
"Unexpected Exception: " + ex);
85 public static bool SafeCall(
this AndroidJavaObject obj,
string methodName, params
object[] args)
94 if (args ==
null || args.Length == 0)
97 obj.Call(methodName, args);
100 catch (AndroidJavaException e)
102 Debug.unityLogger.Log(LogType.Exception,
TAG,
"JNI Exception: " + e);
107 Debug.unityLogger.Log(LogType.Exception,
TAG,
"Unexpected Exception: " + ex);
120 public static ReturnType
SafeCall<ReturnType>(
this AndroidJavaObject obj,
string methodName, params
object[] args)
129 if (args ==
null || args.Length == 0)
130 return obj.Call<ReturnType>(methodName);
132 return obj.Call<ReturnType>(methodName, args);
134 catch (AndroidJavaException e)
136 Debug.unityLogger.Log(LogType.Exception,
TAG,
"JNI Exception: " + e);
141 Debug.unityLogger.Log(LogType.Exception,
TAG,
"Unexpected Exception: " + ex);
162 return obj.GetStatic<ReturnType>(fieldName);
164 catch (AndroidJavaException e)
166 Debug.unityLogger.Log(LogType.Exception,
TAG,
"JNI Exception: " + e);
171 Debug.unityLogger.Log(LogType.Exception,
TAG,
"Unexpected Exception: " + ex);
192 return obj.Get<ReturnType>(fieldName);
194 catch (AndroidJavaException e)
196 Debug.unityLogger.Log(LogType.Exception,
TAG,
"JNI Exception: " + e);
201 Debug.unityLogger.Log(LogType.Exception,
TAG,
"Unexpected Exception: " + ex);
static ReturnType SafeGetStatic< ReturnType >(this AndroidJavaObject obj, string fieldName)
Gets a static field of a native object.
static ReturnType SafeCallStatic< ReturnType >(this AndroidJavaObject obj, string methodName, params object[] args)
Calls a static method on a native object using method name with optional arguments,...
static bool SafeCall(this AndroidJavaObject obj, string methodName, params object[] args)
Calls a void method on a native object using method name with optional arguments.
static bool SafeCallStatic(this AndroidJavaObject obj, string methodName, params object[] args)
Calls a static void method on a native object using method name with optional arguments.
static ReturnType SafeGet< ReturnType >(this AndroidJavaObject obj, string fieldName)
Gets a field of a native object.
static ReturnType SafeCall< ReturnType >(this AndroidJavaObject obj, string methodName, params object[] args)
Calls a method on a native object using method name with optional parameters, and returns the result.