CallStringMethod() public static method

public static CallStringMethod ( IntPtr obj, IntPtr methodID, jvalue args ) : string
obj System.IntPtr
methodID System.IntPtr
args jvalue
return string
Exemplo n.º 1
0
        public static void CheckException()
        {
            IntPtr intPtr = AndroidJNI.ExceptionOccurred();
            bool   flag   = intPtr != IntPtr.Zero;

            if (flag)
            {
                AndroidJNI.ExceptionClear();
                IntPtr intPtr2 = AndroidJNI.FindClass("java/lang/Throwable");
                IntPtr intPtr3 = AndroidJNI.FindClass("android/util/Log");
                try
                {
                    IntPtr   methodID       = AndroidJNI.GetMethodID(intPtr2, "toString", "()Ljava/lang/String;");
                    IntPtr   staticMethodID = AndroidJNI.GetStaticMethodID(intPtr3, "getStackTraceString", "(Ljava/lang/Throwable;)Ljava/lang/String;");
                    string   message        = AndroidJNI.CallStringMethod(intPtr, methodID, new jvalue[0]);
                    jvalue[] array          = new jvalue[1];
                    array[0].l = intPtr;
                    string javaStackTrace = AndroidJNI.CallStaticStringMethod(intPtr3, staticMethodID, array);
                    throw new AndroidJavaException(message, javaStackTrace);
                }
                finally
                {
                    AndroidJNISafe.DeleteLocalRef(intPtr);
                    AndroidJNISafe.DeleteLocalRef(intPtr2);
                    AndroidJNISafe.DeleteLocalRef(intPtr3);
                }
            }
        }
Exemplo n.º 2
0
        public static void CheckException()
        {
            IntPtr jthrowable = AndroidJNI.ExceptionOccurred();

            if (jthrowable != IntPtr.Zero)
            {
                AndroidJNI.ExceptionClear();
                IntPtr jthrowableClass     = AndroidJNI.FindClass("java/lang/Throwable");
                IntPtr androidUtilLogClass = AndroidJNI.FindClass("android/util/Log");
                try
                {
                    IntPtr toStringMethodId            = AndroidJNI.GetMethodID(jthrowableClass, "toString", "()Ljava/lang/String;");
                    IntPtr getStackTraceStringMethodId = AndroidJNI.GetStaticMethodID(androidUtilLogClass, "getStackTraceString", "(Ljava/lang/Throwable;)Ljava/lang/String;");
                    string exceptionMessage            = AndroidJNI.CallStringMethod(jthrowable, toStringMethodId, new jvalue[] {});
                    // Pass jthrowable as a param to getStackTraceString()
                    jvalue[] jniArgs = new jvalue[1];
                    jniArgs[0].l = jthrowable;
                    string exceptionCallStack = AndroidJNI.CallStaticStringMethod(androidUtilLogClass, getStackTraceStringMethodId, jniArgs);
                    throw new AndroidJavaException(exceptionMessage, exceptionCallStack);
                }
                finally
                {
                    AndroidJNISafe.DeleteLocalRef(jthrowable);
                    AndroidJNISafe.DeleteLocalRef(jthrowableClass);
                    AndroidJNISafe.DeleteLocalRef(androidUtilLogClass);
                }
            }
        }
Exemplo n.º 3
0
        public static void CheckException()
        {
            IntPtr localref = AndroidJNI.ExceptionOccurred();

            if (!(localref != IntPtr.Zero))
            {
                return;
            }
            AndroidJNI.ExceptionClear();
            IntPtr num1 = AndroidJNI.FindClass("java/lang/Throwable");
            IntPtr num2 = AndroidJNI.FindClass("android/util/Log");

            try
            {
                IntPtr   methodId       = AndroidJNI.GetMethodID(num1, "toString", "()Ljava/lang/String;");
                IntPtr   staticMethodId = AndroidJNI.GetStaticMethodID(num2, "getStackTraceString", "(Ljava/lang/Throwable;)Ljava/lang/String;");
                string   message        = AndroidJNI.CallStringMethod(localref, methodId, new jvalue[0]);
                jvalue[] args           = new jvalue[1];
                args[0].l = localref;
                string javaStackTrace = AndroidJNI.CallStaticStringMethod(num2, staticMethodId, args);
                throw new AndroidJavaException(message, javaStackTrace);
            }
            finally
            {
                AndroidJNISafe.DeleteLocalRef(localref);
                AndroidJNISafe.DeleteLocalRef(num1);
                AndroidJNISafe.DeleteLocalRef(num2);
            }
        }
Exemplo n.º 4
0
        public static void CheckException()
        {
            IntPtr ptr = AndroidJNI.ExceptionOccurred();

            if (ptr != IntPtr.Zero)
            {
                AndroidJNI.ExceptionClear();
                IntPtr clazz = AndroidJNI.FindClass("java/lang/Throwable");
                IntPtr ptr3  = AndroidJNI.FindClass("android/util/Log");
                try
                {
                    IntPtr   methodID = AndroidJNI.GetMethodID(clazz, "toString", "()Ljava/lang/String;");
                    IntPtr   ptr5     = AndroidJNI.GetStaticMethodID(ptr3, "getStackTraceString", "(Ljava/lang/Throwable;)Ljava/lang/String;");
                    string   message  = AndroidJNI.CallStringMethod(ptr, methodID, new jvalue[0]);
                    jvalue[] args     = new jvalue[1];
                    args[0].l = ptr;
                    string javaStackTrace = AndroidJNI.CallStaticStringMethod(ptr3, ptr5, args);
                    throw new AndroidJavaException(message, javaStackTrace);
                }
                finally
                {
                    DeleteLocalRef(ptr);
                    DeleteLocalRef(clazz);
                    DeleteLocalRef(ptr3);
                }
            }
        }
Exemplo n.º 5
0
 public static string CallStringMethod(IntPtr obj, IntPtr methodID, jvalue[] args)
 {
     try
     {
         return(AndroidJNI.CallStringMethod(obj, methodID, args));
     }
     finally
     {
         AndroidJNISafe.CheckException();
     }
 }
Exemplo n.º 6
0
        public static string CallStringMethod(IntPtr obj, IntPtr methodID, jvalue[] args)
        {
            string str;

            try
            {
                str = AndroidJNI.CallStringMethod(obj, methodID, args);
            }
            finally
            {
                CheckException();
            }
            return(str);
        }
Exemplo n.º 7
0
        public static void CheckException()
        {
            IntPtr ptr = AndroidJNI.ExceptionOccurred();

            if (ptr != IntPtr.Zero)
            {
                AndroidJNI.ExceptionClear();
                IntPtr clazz = AndroidJNI.FindClass("java/lang/Throwable");
                try
                {
                    IntPtr methodID = AndroidJNI.GetMethodID(clazz, "toString", "()Ljava/lang/String;");
                    throw new AndroidJavaException(AndroidJNI.CallStringMethod(ptr, methodID, new jvalue[0]));
                }
                finally
                {
                    DeleteLocalRef(ptr);
                    DeleteLocalRef(clazz);
                }
            }
        }