9 const string TAG =
"SafeJNI";
18 public static bool SafeCallStatic(
this AndroidJavaObject obj,
string methodName, params
object[] args)
27 if (args ==
null || args.Length == 0)
28 obj.CallStatic(methodName);
30 obj.CallStatic(methodName, args);
33 catch (AndroidJavaException e)
35 Debug.unityLogger.Log(LogType.Exception,
TAG,
"JNI Exception: " + e);
40 Debug.unityLogger.Log(LogType.Exception,
TAG,
"Unexpected Exception: " + ex);
62 if (args ==
null || args.Length == 0)
63 return obj.CallStatic<ReturnType>(methodName);
65 return obj.CallStatic<ReturnType>(methodName, args);
67 catch (AndroidJavaException e)
69 Debug.unityLogger.Log(LogType.Exception,
TAG,
"JNI Exception: " + e);
74 Debug.unityLogger.Log(LogType.Exception,
TAG,
"Unexpected Exception: " + ex);
86 public static bool SafeCall(
this AndroidJavaObject obj,
string methodName, params
object[] args)
95 if (args ==
null || args.Length == 0)
98 obj.Call(methodName, args);
101 catch (AndroidJavaException e)
103 Debug.unityLogger.Log(LogType.Exception,
TAG,
"JNI Exception: " + e);
108 Debug.unityLogger.Log(LogType.Exception,
TAG,
"Unexpected Exception: " + ex);
121 public static ReturnType
SafeCall<ReturnType>(
this AndroidJavaObject obj,
string methodName, params
object[] args)
130 if (args ==
null || args.Length == 0)
131 return obj.Call<ReturnType>(methodName);
133 return obj.Call<ReturnType>(methodName, args);
135 catch (AndroidJavaException e)
137 Debug.unityLogger.Log(LogType.Exception,
TAG,
"JNI Exception: " + e);
142 Debug.unityLogger.Log(LogType.Exception,
TAG,
"Unexpected Exception: " + ex);
163 return obj.GetStatic<ReturnType>(fieldName);
165 catch (AndroidJavaException e)
167 Debug.unityLogger.Log(LogType.Exception,
TAG,
"JNI Exception: " + e);
172 Debug.unityLogger.Log(LogType.Exception,
TAG,
"Unexpected Exception: " + ex);
193 return obj.Get<ReturnType>(fieldName);
195 catch (AndroidJavaException e)
197 Debug.unityLogger.Log(LogType.Exception,
TAG,
"JNI Exception: " + e);
202 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.