Esempio n. 1
0
        private void AndroidJNISafeCheckException()
        {
            IntPtr intPtr = AndroidJNI.ExceptionOccurred();

            if (intPtr != IntPtr.Zero)
            {
                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
                {
                    AndroidJNISafeDeleteLocalRef(intPtr);
                    AndroidJNISafeDeleteLocalRef(intPtr2);
                    AndroidJNISafeDeleteLocalRef(intPtr3);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Throws one of the exceptions (<c>UserProfileNotFoundException</c> or <c>ProviderNotFoundException</c> if needed.
        /// </summary>
        public static void checkExceptions()
        {
            IntPtr jException = AndroidJNI.ExceptionOccurred();

            if (jException != IntPtr.Zero)
            {
                AndroidJNI.ExceptionClear();

                AndroidJavaClass jniExceptionClass = new AndroidJavaClass("com.soomla.profile.exceptions.UserProfileNotFoundException");
                if (AndroidJNI.IsInstanceOf(jException, jniExceptionClass.GetRawClass()))
                {
                    Debug.Log("SOOMLA/UNITY Caught UserProfileNotFoundException!");

                    throw new UserProfileNotFoundException();
                }

                jniExceptionClass.Dispose();
                jniExceptionClass = new AndroidJavaClass("com.soomla.profile.exceptions.ProviderNotFoundException");
                if (AndroidJNI.IsInstanceOf(jException, jniExceptionClass.GetRawClass()))
                {
                    Debug.Log("SOOMLA/UNITY Caught ProviderNotFoundException!");

                    throw new ProviderNotFoundException();
                }

                jniExceptionClass.Dispose();

                Debug.Log("SOOMLA/UNITY Got an exception but can't identify it!");
            }
        }
        public static void CheckException()
        {
            IntPtr localref = AndroidJNI.ExceptionOccurred();

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

            try {
                IntPtr methodId       = AndroidJNI.GetMethodID(class1, "toString", "()Ljava/lang/String;");
                IntPtr staticmethodId = AndroidJNI.GetStaticMethodID(class2, "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(class2, staticmethodId, args);
                throw new AndroidJavaException(message, javaStackTrace);
            }
            finally {
                DeleteLocalRef(localref);
                DeleteLocalRef(class1);
                DeleteLocalRef(class2);
            }
        }
Esempio n. 4
0
    // 检查用户是否已登录九城游戏中心
    public bool isUserLoggedIn()
    {
        bool isUserLoggedIn = cls_OpenFeint.CallStatic <bool>("isUserLoggedIn");

        if (AndroidJNI.ExceptionOccurred() != IntPtr.Zero)              // will return NullPointerException if not logged in
        {
            AndroidJNI.ExceptionClear();
            return(false);
        }

        return(isUserLoggedIn);
    }
            static IntPtr GetJavaMethodID(IntPtr classId, string name, string sig)
            {
                AndroidJNI.ExceptionClear();
                var mid = AndroidJNI.GetMethodID(classId, name, sig);

                IntPtr ex = AndroidJNI.ExceptionOccurred();
                if (ex != (IntPtr)0)
                {
                    AndroidJNI.ExceptionDescribe();
                    AndroidJNI.ExceptionClear();
                    return (IntPtr)0;
                }
                else
                {
                    return mid;
                }
            }
 public double GetHighPrecisionSkinTempLevel()
 {
     double currentTempLevel = -1.0;
     try
     {
         currentTempLevel = AndroidJNI.CallDoubleMethod(s_GameSDKRawObjectID, s_GetHighPrecisionSkinTempLevelID, s_NoArgs);
         if (AndroidJNI.ExceptionOccurred() != IntPtr.Zero)
         {
             AndroidJNI.ExceptionDescribe();
             AndroidJNI.ExceptionClear();
         }
     }
     catch (Exception)
     {
         GameSDKLog.Debug("[Exception] GameSDK.getHighPrecisionSkinTempLevel() failed!");
     }
     return currentTempLevel;
 }
 public int GetSkinTempLevel()
 {
     int currentTempLevel = -1;
     try
     {
         currentTempLevel = AndroidJNI.CallIntMethod(s_GameSDKRawObjectID, s_GetSkinTempLevelID, s_NoArgs);
         if (AndroidJNI.ExceptionOccurred() != IntPtr.Zero)
         {
             AndroidJNI.ExceptionDescribe();
             AndroidJNI.ExceptionClear();
         }
     }
     catch (Exception)
     {
         GameSDKLog.Debug("[Exception] GameSDK.getSkinTempLevel() failed!");
     }
     return currentTempLevel;
 }
            public double GetGpuFrameTime()
            {
                double gpuFrameTime = -1.0;
                try
                {
                    gpuFrameTime = AndroidJNI.CallDoubleMethod(s_GameSDKRawObjectID, s_GetGpuFrameTimeID, s_NoArgs);
                    if (AndroidJNI.ExceptionOccurred() != IntPtr.Zero)
                    {
                        AndroidJNI.ExceptionDescribe();
                        AndroidJNI.ExceptionClear();
                    }
                }
                catch (Exception)
                {
                    GameSDKLog.Debug("[Exception] GameSDK.getGpuFrameTime() failed!");
                }

                return gpuFrameTime;
            }
Esempio n. 9
0
        public static void checkExceptions()
        {
            IntPtr jException = AndroidJNI.ExceptionOccurred();

            if (jException != IntPtr.Zero)
            {
                using (AndroidJavaObject exception = new AndroidJavaObject(jException)) {
                    AndroidJNI.ExceptionClear();

                    AndroidJavaClass jniExceptionClass = new AndroidJavaClass("com.soomla.store.exceptions.InsufficientFundsException");
                    if (AndroidJNI.IsInstanceOf(exception.GetRawObject(), jniExceptionClass.GetRawClass()))
                    {
                        Debug.Log("SOOMLA/UNITY Cought InsufficientFundsException!");

                        throw new InsufficientFundsException();
                    }

                    jniExceptionClass.Dispose();
                    jniExceptionClass = new AndroidJavaClass("com.soomla.store.exceptions.VirtualItemNotFoundException");
                    if (AndroidJNI.IsInstanceOf(exception.GetRawObject(), jniExceptionClass.GetRawClass()))
                    {
                        Debug.Log("SOOMLA/UNITY Cought VirtualItemNotFoundException!");

                        throw new VirtualItemNotFoundException();
                    }

                    jniExceptionClass.Dispose();
                    jniExceptionClass = new AndroidJavaClass("com.soomla.store.exceptions.NotEnoughGoodsException");
                    if (AndroidJNI.IsInstanceOf(exception.GetRawObject(), jniExceptionClass.GetRawClass()))
                    {
                        Debug.Log("SOOMLA/UNITY Cought NotEnoughGoodsException!");

                        throw new NotEnoughGoodsException();
                    }

                    jniExceptionClass.Dispose();
                }

                Debug.Log("SOOMLA/UNITY Got an exception but can't identify it!");
            }
        }
    public static void FetchOBB()
    {
        using (AndroidJavaClass unity_player = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
        {
            AndroidJavaObject current_activity = unity_player.GetStatic <AndroidJavaObject>("currentActivity");

            AndroidJavaObject intent = new AndroidJavaObject("android.content.Intent",
                                                             current_activity,
                                                             new AndroidJavaClass("com.unity3d.plugin.downloader.UnityDownloaderActivity"));

            int Intent_FLAG_ACTIVITY_NO_ANIMATION = 0x10000;
            intent.Call <AndroidJavaObject>("addFlags", Intent_FLAG_ACTIVITY_NO_ANIMATION);
            intent.Call <AndroidJavaObject>("putExtra", "unityplayer.Activity",
                                            current_activity.Call <AndroidJavaObject>("getClass").Call <string>("getName"));
            current_activity.Call("startActivity", intent);

            if (AndroidJNI.ExceptionOccurred() != System.IntPtr.Zero)
            {
                Debug.LogError("Exception occurred while attempting to start DownloaderActivity - is the AndroidManifest.xml incorrect?");
                AndroidJNI.ExceptionDescribe();
                AndroidJNI.ExceptionClear();
            }
        }
    }
 public static void FetchOBB()
 {
     using (AndroidJavaClass androidJavaClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
     {
         AndroidJavaObject @static           = androidJavaClass.GetStatic <AndroidJavaObject>("currentActivity");
         AndroidJavaObject androidJavaObject = new AndroidJavaObject("android.content.Intent", @static, new AndroidJavaClass("com.unity3d.plugin.downloader.UnityDownloaderActivity"));
         int num = 65536;
         androidJavaObject.Call <AndroidJavaObject>("addFlags", new object[1] {
             num
         });
         androidJavaObject.Call <AndroidJavaObject>("putExtra", new object[2]
         {
             "unityplayer.Activity",
             @static.Call <AndroidJavaObject>("getClass", new object[0]).Call <string>("getName", new object[0])
         });
         @static.Call("startActivity", androidJavaObject);
         if (AndroidJNI.ExceptionOccurred() != IntPtr.Zero)
         {
             Debug.LogError("Exception occurred while attempting to start DownloaderActivity - is the AndroidManifest.xml incorrect?");
             AndroidJNI.ExceptionDescribe();
             AndroidJNI.ExceptionClear();
         }
     }
 }
Esempio n. 12
0
    public static void init()
    {
        if (Application.get_platform() != 11)
        {
            return;
        }
        try
        {
            using (AndroidJavaClass androidJavaClass = new AndroidJavaClass("com.upsight.android.unity.UpsightPlugin"))
            {
                if (((AndroidJavaObject)androidJavaClass).CallStatic <bool>("isEnabled", new object[0]) == null)
                {
                    Debug.LogWarning((object)"Upsight.init() was called but the SDK is currently disabled from the Upsight SDK Management Extension. Upsight will not initialize.");
                    return;
                }
            }
        }
        catch
        {
            Debug.LogError((object)"Error while checking if the Upsight SDK is enabled. Unable to initialize");
            return;
        }
        if (Upsight.Initialized)
        {
            return;
        }
        Upsight.Initialized = true;
        UpsightManager.init();
        try
        {
            Upsight._pluginBase = new AndroidJavaObject("com.upsight.android.unity.UpsightPlugin", new object[0]);
            if (Upsight._pluginBase != null)
            {
                if (!(AndroidJNI.ExceptionOccurred() != IntPtr.Zero))
                {
                    goto label_15;
                }
            }
            Debug.LogError((object)"Upsight initialization failed! JNI Exception thrown:");
            AndroidJNI.ExceptionDescribe();
            Upsight._pluginBase = (AndroidJavaObject)null;
            AndroidJNI.ExceptionClear();
            return;
        }
        catch (Exception ex)
        {
            Debug.LogError((object)"Upsight initialization failed!");
            Debug.LogException(ex);
            Upsight._pluginBase = (AndroidJavaObject)null;
            return;
        }
label_15:
        try
        {
            Upsight._pluginMarketingExtension = new AndroidJavaObject("com.upsight.android.unity.UpsightMarketingManager", new object[0]);
            if (Upsight._pluginMarketingExtension != null)
            {
                Upsight._pluginBase.Call("registerExtension", new object[1]
                {
                    (object)Upsight._pluginMarketingExtension
                });
            }
        }
        catch
        {
            Debug.LogWarning((object)"Upsight Marketing Extension not included.");
            Upsight._pluginMarketingExtension = (AndroidJavaObject)null;
        }
        try
        {
            Upsight._pluginPushExtension = new AndroidJavaObject("com.upsight.android.unity.UpsightPushManager", new object[0]);
            if (Upsight._pluginPushExtension == null)
            {
                return;
            }
            Upsight._pluginBase.Call("registerExtension", new object[1]
            {
                (object)Upsight._pluginPushExtension
            });
        }
        catch
        {
            Debug.LogWarning((object)"Upsight Push Extension not included.");
            Upsight._pluginPushExtension = (AndroidJavaObject)null;
        }
    }