public static T StaticInvokeObjectCall <T>(string type, string name, string sig, params object[] args)
        {
            IntPtr intPtr         = AndroidJNI.FindClass(type);
            IntPtr staticMethodID = AndroidJNI.GetStaticMethodID(intPtr, name, sig);

            jvalue[]        array       = ConstructArgArray(args);
            IntPtr          intPtr2     = AndroidJNI.CallStaticObjectMethod(intPtr, staticMethodID, array);
            ConstructorInfo constructor = typeof(T).GetConstructor(new Type[1]
            {
                intPtr2.GetType()
            });

            if (constructor != null)
            {
                return((T)constructor.Invoke(new object[1]
                {
                    intPtr2
                }));
            }
            if (typeof(T).IsArray)
            {
                return(AndroidJNIHelper.ConvertFromJNIArray <T>(intPtr2));
            }
            Debug.Log((object)"Trying cast....");
            Type typeFromHandle = typeof(T);

            return((T)Marshal.PtrToStructure(intPtr2, typeFromHandle));
        }
예제 #2
0
        /// <summary>
        /// Calls a static method with an object return type.
        /// </summary>
        /// <returns>The invoke call.</returns>
        /// <param name="type">Type.</param>
        /// <param name="name">Name.</param>
        /// <param name="sig">Sig.</param>
        /// <param name="args">Arguments.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public static T StaticInvokeObjectCall <T>(
            string type, string name, string sig, params object[] args)
        {
            IntPtr rawClass = AndroidJNI.FindClass(type);
            IntPtr method   = AndroidJNI.GetStaticMethodID(rawClass, name, sig);

            jvalue[] jArgs = ConstructArgArray(args);

            try
            {
                IntPtr          val = AndroidJNI.CallStaticObjectMethod(rawClass, method, jArgs);
                ConstructorInfo c   = typeof(T).GetConstructor(new Type[] { val.GetType() });
                if (c != null)
                {
                    return((T)c.Invoke(new object[] { val }));
                }
                if (typeof(T).IsArray)
                {
                    // make an array
                    //TODO: handle arrays of objects
                    return(AndroidJNIHelper.ConvertFromJNIArray <T>(val));
                }
                Debug.Log("Trying cast....");
                Type t = typeof(T);
                return((T)Marshal.PtrToStructure(val, t));
            }
            finally
            {
                AndroidJNIHelper.DeleteJNIArgArray(args, jArgs);
            }
        }
예제 #3
0
        public static IntPtr CreateInvisibleView()
        {
            object[] objectArray = new object[1];
            jvalue[] jArgs       = AndroidJNIHelper.CreateJNIArgArray(objectArray);

            try
            {
                using (var bridgeClass = new AndroidJavaClass(TokenFragmentClass))
                {
                    using (var currentActivity = GetActivity())
                    {
                        // Unity no longer supports constructing an AndroidJavaObject using an IntPtr,
                        // so I have to manually munge with JNI here.
                        IntPtr methodId = AndroidJNI.GetStaticMethodID(bridgeClass.GetRawClass(),
                                                                       "createInvisibleView",
                                                                       "(Landroid/app/Activity;)Landroid/view/View;");
                        jArgs[0].l = currentActivity.GetRawObject();

                        IntPtr view =
                            AndroidJNI.CallStaticObjectMethod(bridgeClass.GetRawClass(), methodId, jArgs);
                        return(view);
                    }
                }
            }
            catch (Exception e)
            {
                OurUtils.Logger.e("Exception creating invisible view: " + e.Message);
                OurUtils.Logger.e(e.ToString());
            }
            finally
            {
                AndroidJNIHelper.DeleteJNIArgArray(objectArray, jArgs);
            }
            return(IntPtr.Zero);
        }
예제 #4
0
    public void InitPlugin()
    {
        unityClass  = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        pluginClass = new AndroidJavaClass("com.TL.openfile.FileOpener");

        instancePtr = AndroidJNI.CallStaticObjectMethod(pluginClass.GetRawClass(), AndroidJNI.GetStaticMethodID(pluginClass.GetRawClass(), "instance",
                                                                                                                "()Lcom/TL/openfile/FileOpener;"), new jvalue[] { });

        // currentActivityPtr = AndroidJNI.GetStaticObjectField
        // (
        //  unityClass.GetRawClass(), AndroidJNI.GetStaticFieldID
        //  (
        //      unityClass.GetRawClass(), "currentActivity", "Landroid/app/Activity;"
        //  )
        // );

        downloadDirectory = AndroidJNI.CallStaticStringMethod
                            (
            instancePtr, AndroidJNI.GetMethodID
            (
                pluginClass.GetRawClass(), "GetDownloadDirectory", "()Ljava/lang/String;"
            ),
            new jvalue[]
        {
        }
                            );
        print("DownloadDirectory " + downloadDirectory);
        downloadDirectory = "/storage/emulated/0/";
        print("DownloadDirectory " + downloadDirectory);
    }
예제 #5
0
        public static OuyaContent getOuyaContent()
        {
#if VERBOSE_LOGGING
            Debug.Log(string.Format("Invoking {0}...", MethodBase.GetCurrentMethod().Name));
#endif
            JNIFind();

            if (_jcOuyaUnityPlugin == IntPtr.Zero)
            {
                Debug.LogError("_jcOuyaUnityPlugin is not initialized");
                return(null);
            }
            if (_jmGetOuyaContent == IntPtr.Zero)
            {
                Debug.LogError("_jmGetOuyaContent is not initialized");
                return(null);
            }
            IntPtr retVal = AndroidJNI.CallStaticObjectMethod(_jcOuyaUnityPlugin, _jmGetOuyaContent, new jvalue[0] {
            });
            if (retVal == IntPtr.Zero)
            {
                Debug.LogError("GetOuyaContent returned null");
                return(null);
            }
            IntPtr globalPtr = AndroidJNI.NewGlobalRef(retVal);
            AndroidJNI.DeleteLocalRef(retVal);
            return(new OuyaContent(globalPtr));
        }
예제 #6
0
        public static void requestProducts(string jsonData)
        {
#if VERBOSE_LOGGING
            Debug.Log(string.Format("Invoking {0}...", MethodBase.GetCurrentMethod().Name));
#endif
            JNIFind();

            if (_jcOuyaUnityPlugin == IntPtr.Zero)
            {
                Debug.LogError("_jcOuyaUnityPlugin is not initialized");
                return;
            }
            if (_jmRequestProducts == IntPtr.Zero)
            {
                Debug.LogError("_jmGetProductsAsync is not initialized");
                return;
            }

            // Make one request at a time
            if (m_pendingRequestProducts)
            {
                return;
            }
            m_pendingRequestProducts = true;

            IntPtr arg1   = AndroidJNI.NewStringUTF(jsonData);
            IntPtr result = AndroidJNI.CallStaticObjectMethod(_jcOuyaUnityPlugin, _jmRequestProducts, new jvalue[] { new jvalue()
                                                                                                                     {
                                                                                                                         l = arg1
                                                                                                                     } });
            AndroidJNI.DeleteLocalRef(arg1);
        }
예제 #7
0
        public static string getGameData(string key)
        {
#if VERBOSE_LOGGING
            Debug.Log(string.Format("Invoking {0}...", MethodBase.GetCurrentMethod().Name));
#endif
            JNIFind();

            if (_jcOuyaUnityPlugin == IntPtr.Zero)
            {
                Debug.LogError("_jcOuyaUnityPlugin is not initialized");
                return(null);
            }
            if (_jmGetGameData == IntPtr.Zero)
            {
                Debug.LogError("_jmGetGameData is not initialized");
                return(null);
            }
            IntPtr arg1   = AndroidJNI.NewStringUTF(key);
            IntPtr result = AndroidJNI.CallStaticObjectMethod(_jcOuyaUnityPlugin, _jmGetGameData, new jvalue[] { new jvalue()
                                                                                                                 {
                                                                                                                     l = arg1
                                                                                                                 } });
            AndroidJNI.DeleteLocalRef(arg1);

            if (result == IntPtr.Zero)
            {
                Debug.LogError("Failed to getGameData");
                return(null);
            }

            String retVal = AndroidJNI.GetStringUTFChars(result);
            return(retVal);
        }
예제 #8
0
        private static string InternalGetPersistentDataPath()
        {
            string path = "";

            try
            {
                IntPtr obj_context = AndroidJNI.FindClass("android/os/Environment");
                IntPtr method_getExternalStorageDirectory = AndroidJNIHelper.GetMethodID(obj_context, "getExternalStorageDirectory", "()Ljava/io/File;", true);
                IntPtr file     = AndroidJNI.CallStaticObjectMethod(obj_context, method_getExternalStorageDirectory, new jvalue[0]);
                IntPtr obj_file = AndroidJNI.FindClass("java/io/File");
                IntPtr method_getAbsolutePath = AndroidJNIHelper.GetMethodID(obj_file, "getAbsolutePath", "()Ljava/lang/String;");

                path = AndroidJNI.CallStringMethod(file, method_getAbsolutePath, new jvalue[0]);

                if (path != null)
                {
                    path += "/Android/data/" + GetPackageName() + "/files";
                }
                else
                {
                    path = "";
                }
            }
            catch (Exception e)
            {
                Debug.Log(e.ToString());
            }
            return(path);
        }
예제 #9
0
        public static string getGameData(string key)
        {
            if (_jcOuyaUnityPlugin == IntPtr.Zero)
            {
                Debug.LogError("_jcOuyaUnityPlugin is not initialized");
                return(null);
            }
            if (_jmGetGameData == IntPtr.Zero)
            {
                Debug.LogError("_jmGetGameData is not initialized");
                return(null);
            }
            IntPtr arg1   = AndroidJNI.NewStringUTF(key);
            IntPtr result = AndroidJNI.CallStaticObjectMethod(_jcOuyaUnityPlugin, _jmGetGameData, new jvalue[] { new jvalue()
                                                                                                                 {
                                                                                                                     l = arg1
                                                                                                                 } });

            AndroidJNI.DeleteLocalRef(arg1);

            if (result == IntPtr.Zero)
            {
                Debug.LogError("Failed to getGameData");
                return(null);
            }

            String retVal = AndroidJNI.GetStringUTFChars(result);

            return(retVal);
        }
예제 #10
0
        public static T StaticInvokeObjectCall <T>(string type, string name, string sig, params object[] args)
        {
            IntPtr num            = AndroidJNI.FindClass(type);
            IntPtr staticMethodId = AndroidJNI.GetStaticMethodID(num, name, sig);

            jvalue[]        jvalueArray = JavaObjWrapper.ConstructArgArray(args);
            IntPtr          ptr         = AndroidJNI.CallStaticObjectMethod(num, staticMethodId, jvalueArray);
            ConstructorInfo constructor = typeof(T).GetConstructor(new Type[1] {
                ptr.GetType()
            });

            if ((object)constructor != null)
            {
                return((T)constructor.Invoke(new object[1] {
                    (object)ptr
                }));
            }
            if (typeof(T).IsArray)
            {
                return(AndroidJNIHelper.ConvertFromJNIArray <T>(ptr));
            }
            Debug.Log((object)"Trying cast....");
            Type structureType = typeof(T);

            return((T)Marshal.PtrToStructure(ptr, structureType));
        }
예제 #11
0
        // STATIC

        public static string CallStaticStr(this AndroidJavaObject ajo, string methodName, params object[] args)
        {
#if UNITY_2018_2_OR_NEWER
            // A fix for a regression issue introduced in Unity 2018.2
            // Details: https://issuetracker.unity3d.com/issues/android-androidjavaobject-dot-call-crashes-with-fatal-signal-11-sigsegv

            var rawClass = ajo.GetRawClass();
            if (args == null)
            {
                args = new object[] { null };
            }
            IntPtr   methodID = AndroidJNIHelper.GetMethodID <string>(rawClass, methodName, args, true);
            jvalue[] jniArgs  = AndroidJNIHelper.CreateJNIArgArray(args);

            try
            {
                IntPtr returnValue = AndroidJNI.CallStaticObjectMethod(rawClass, methodID, jniArgs);
                if (IntPtr.Zero != returnValue)
                {
                    var val = AndroidJNI.GetStringUTFChars(returnValue);
                    AndroidJNI.DeleteLocalRef(returnValue);
                    return(val);
                }
            }
            finally
            {
                AndroidJNIHelper.DeleteJNIArgArray(args, jniArgs);
            }

            return(null);
#else
            return(CallStaticSafe <string>(ajo, methodName, args));
#endif
        }
예제 #12
0
        public static T StaticInvokeObjectCall <T>(string type, string name, string sig, params object[] args)
        {
            IntPtr clazz    = AndroidJNI.FindClass(type);
            IntPtr methodID = AndroidJNI.GetStaticMethodID(clazz, name, sig);

            jvalue[] jvalueArray = ConstructArgArray(args);
            IntPtr   array       = AndroidJNI.CallStaticObjectMethod(clazz, methodID, jvalueArray);

            Type[]          types       = new Type[] { array.GetType() };
            ConstructorInfo constructor = typeof(T).GetConstructor(types);

            if (constructor != null)
            {
                object[] parameters = new object[] { array };
                return((T)constructor.Invoke(parameters));
            }
            if (typeof(T).IsArray)
            {
                return(AndroidJNIHelper.ConvertFromJNIArray <T>(array));
            }
            Debug.Log("Trying cast....");
            Type structureType = typeof(T);

            return((T)Marshal.PtrToStructure(array, structureType));
        }
예제 #13
0
        private IntPtr CallNativeObjectMethodRef(string methodName, string methodSig, object[] args)
        {
            if (!CanRunJNI())
            {
                return(IntPtr.Zero);
            }
            bool isAttached = bsg_unity_isJNIAttached();

            if (!isAttached)
            {
                AndroidJNI.AttachCurrentThread();
            }

            jvalue[] jargs       = AndroidJNIHelper.CreateJNIArgArray(args);
            IntPtr   methodID    = AndroidJNI.GetStaticMethodID(BugsnagNativeInterface, methodName, methodSig);
            IntPtr   nativeValue = AndroidJNI.CallStaticObjectMethod(BugsnagNativeInterface, methodID, jargs);

            AndroidJNIHelper.DeleteJNIArgArray(args, jargs);

            if (!isAttached)
            {
                AndroidJNI.DetachCurrentThread();
            }
            return(nativeValue);
        }
예제 #14
0
        private string CallNativeStringMethod(string methodName, string methodSig, object[] args)
        {
            if (!CanRunJNI())
            {
                return("");
            }
            bool isAttached = bsg_unity_isJNIAttached();

            if (!isAttached)
            {
                AndroidJNI.AttachCurrentThread();
            }
            var jargs       = AndroidJNIHelper.CreateJNIArgArray(args);
            var methodID    = AndroidJNI.GetStaticMethodID(BugsnagNativeInterface, methodName, methodSig);
            var nativeValue = AndroidJNI.CallStaticObjectMethod(BugsnagNativeInterface, methodID, jargs);

            AndroidJNIHelper.DeleteJNIArgArray(args, jargs);
            string value = null;

            if (nativeValue != null && nativeValue != IntPtr.Zero)
            {
                value = AndroidJNI.GetStringUTFChars(nativeValue);
            }
            if (!isAttached)
            {
                AndroidJNI.DetachCurrentThread();
            }
            return(value);
        }
예제 #15
0
        public static List <Bitmap> getBitmapList(IntPtr list)
        {
#if VERBOSE_LOGGING
            Debug.Log(string.Format("Invoking {0}...", MethodBase.GetCurrentMethod().Name));
#endif
            JNIFind();

            if (_jcOuyaUnityPlugin == IntPtr.Zero)
            {
                Debug.LogError("_jcOuyaUnityPlugin is not initialized");
                return(null);
            }
            if (_jmGetBitmapArray == IntPtr.Zero)
            {
                Debug.LogError("_jmGetBitmapArray is not initialized");
                return(null);
            }

            IntPtr result = AndroidJNI.CallStaticObjectMethod(_jcOuyaUnityPlugin, _jmGetBitmapArray, new jvalue[] { new jvalue()
                                                                                                                    {
                                                                                                                        l = list
                                                                                                                    } });
            if (result == IntPtr.Zero)
            {
                Debug.LogError("_jmGetBitmapArray returned null");
                return(null);
            }

            List <Bitmap> items = new List <Bitmap>();

#if VERBOSE_LOGGING
            Debug.Log("Invoking AndroidJNI.FromObjectArray...");
#endif
            IntPtr[] resultArray = AndroidJNI.FromObjectArray(result);
#if VERBOSE_LOGGING
            Debug.Log("Invoked AndroidJNI.FromObjectArray.");
#endif

            foreach (IntPtr ptr in resultArray)
            {
#if VERBOSE_LOGGING
                Debug.Log("Found Bitmap making Global Ref...");
#endif
                IntPtr globalRef = AndroidJNI.NewGlobalRef(ptr);
                AndroidJNI.DeleteLocalRef(ptr);
#if VERBOSE_LOGGING
                Debug.Log("Made global ref for Bitmap.");
#endif
                Bitmap item = new Bitmap(globalRef);
#if VERBOSE_LOGGING
                Debug.Log("Deleting old bitmap reference...");
#endif
                items.Add(item);
            }
#if VERBOSE_LOGGING
            Debug.Log("Deleting bitmap list reference...");
#endif
            AndroidJNI.DeleteLocalRef(result);
            return(items);
        }
    private void hapticFeedbackWave(long[] times)
    {
        var jVibratorService = new AndroidJavaClass("android.content.Context").GetStatic <string>("VIBRATOR_SERVICE");
        var jVibrator        = jCurrentActivity.Call <AndroidJavaObject>("getSystemService", jVibratorService);

        if (apiLevel >= 26)
        {
            var      jEffectCls = new AndroidJavaClass("android.os.VibrationEffect");
            IntPtr   jTimes     = AndroidJNI.ToLongArray(times);
            jvalue[] jParams1   = new jvalue[2];
            jParams1[0].l = jTimes;
            jParams1[1].i = -1;
            IntPtr jmidCreateWaveForm = AndroidJNIHelper.GetMethodID(jEffectCls.GetRawClass(), "createWaveform", "([JI)Landroid/os/VibrationEffect;", true);
            var    jEffect            = AndroidJNI.CallStaticObjectMethod(jEffectCls.GetRawClass(), jmidCreateWaveForm, jParams1);

            IntPtr   jmidVibrate = AndroidJNIHelper.GetMethodID(jVibrator.GetRawClass(), "vibrate", "(Landroid/os/VibrationEffect;)V");
            jvalue[] jParams2    = new jvalue[2];
            jParams2[0].l = jEffect;
            AndroidJNI.CallVoidMethod(jVibrator.GetRawObject(), jmidVibrate, jParams2);
        }
        else
        {
            jVibrator.Call("vibrate", times);
        }
    }
 public static IntPtr CreateInvisibleView()
 {
     object[] args        = new object[1];
     jvalue[] jvalueArray = AndroidJNIHelper.CreateJNIArgArray(args);
     try
     {
         using (AndroidJavaClass class2 = new AndroidJavaClass("com.google.games.bridge.TokenFragment"))
         {
             using (AndroidJavaObject obj2 = GetActivity())
             {
                 IntPtr methodID = AndroidJNI.GetStaticMethodID(class2.GetRawClass(), "createInvisibleView", "(Landroid/app/Activity;)Landroid/view/View;");
                 jvalueArray[0].l = obj2.GetRawObject();
                 return(AndroidJNI.CallStaticObjectMethod(class2.GetRawClass(), methodID, jvalueArray));
             }
         }
     }
     catch (Exception exception)
     {
         Logger.e("Exception creating invisible view: " + exception.Message);
         Logger.e(exception.ToString());
     }
     finally
     {
         AndroidJNIHelper.DeleteJNIArgArray(args, jvalueArray);
     }
     return(IntPtr.Zero);
 }
예제 #18
0
        public static OuyaController getControllerByPlayer(int deviceId)
        {
            if (_jcOuyaController == IntPtr.Zero)
            {
                Debug.LogError("_jcOuyaController is not initialized");
                return(null);
            }
            if (_jmGetControllerByPlayer == IntPtr.Zero)
            {
                Debug.LogError("_jmGetControllerByPlayer is not initialized");
                return(null);
            }
            IntPtr result = AndroidJNI.CallStaticObjectMethod(_jcOuyaController, _jmGetControllerByPlayer, new jvalue[] { new jvalue()
                                                                                                                          {
                                                                                                                              i = deviceId
                                                                                                                          } });

            if (result == IntPtr.Zero)
            {
                //might not be connected
                //Debug.LogError("Failed to get OuyaController");
                return(null);
            }
            OuyaController retVal = new OuyaController(result);

            return(retVal);
        }
예제 #19
0
        public static ButtonData getButtonData(int button)
        {
            if (_jcOuyaController == IntPtr.Zero)
            {
                Debug.Log("_jcOuyaController is not initialized");
                return(null);
            }
            if (_jmGetButtonData == IntPtr.Zero)
            {
                Debug.LogError("_jmGetButtonData is not initialized");
                return(null);
            }
            IntPtr result = AndroidJNI.CallStaticObjectMethod(_jcOuyaController, _jmGetButtonData, new jvalue[] { new jvalue()
                                                                                                                  {
                                                                                                                      i = button
                                                                                                                  } });

            if (result == IntPtr.Zero)
            {
                Debug.LogError("Failed to get ButtonData");
                return(null);
            }
            ButtonData retVal = new ButtonData();

            retVal.Instance = result;
            return(retVal);
        }
예제 #20
0
    public void InputStreamTest()
    {
        if (Application.platform == RuntimePlatform.Android)
        {
            string strName  = "audiotest/takeleap/com/playsound/PlaySoundExternal";
            IntPtr localRef = AndroidJNI.FindClass(strName);

            IntPtr unityClass       = AndroidJNI.FindClass("com/unity3d/player/UnityPlayer");
            IntPtr inputStreamClass = AndroidJNI.FindClass("java/io/InputStream");

            if (localRef != IntPtr.Zero)
            {
                print("NOT NULL");

                IntPtr instancePtr = AndroidJNI.CallStaticObjectMethod(localRef, AndroidJNI.GetStaticMethodID(localRef, "instance",
                                                                                                              "()Laudiotest/takeleap/com/playsound/PlaySoundExternal;"), new jvalue[] { });

                if (instancePtr != null)
                {
                    print("Instance PTR NOT NULL BRO");
                }
                else
                {
                    print("Instance PTR NULL BRO");
                }

                print(AndroidJNI.CallIntMethod(instancePtr, AndroidJNI.GetMethodID(localRef, "TestPluginNonStatic",
                                                                                   "()I"), new jvalue[] { }));

                // IntPtr currentActivityPtr = AndroidJNI.GetStaticObjectField(unityClass, AndroidJNI.GetStaticFieldID(unityClass, "currentActivity", "Landroid/app/Activity;"));

                // IntPtr inputStreamPtr = AndroidJNI.CallObjectMethod(instancePtr, AndroidJNI.GetMethodID(localRef, "GetInputStream",
                //                                                         "(Landroid/content/Context;)Ljava/io/InputStream;"),
                //                                                         AndroidJNIHelper.CreateJNIArgArray(new object[] { currentActivityPtr }));

                // if (inputStreamPtr != null)
                // {
                //     print("INPUT STREAM NOT NULL");

                //     byte[] buffer = new byte[300];
                //     jvalue[] args = AndroidJNIHelper.CreateJNIArgArray(new object[] { buffer });

                //     int numRead = AndroidJNI.CallIntMethod(inputStreamPtr, AndroidJNI.GetMethodID(inputStreamClass, "read", "([B)I"), args);

                //     print(numRead);
                // }
                // else
                // {
                //     print("INPUT STREAM IS NULL");
                // }

                print("END");
            }
            else
            {
                print("IS NULL");
            }
        }
    }
예제 #21
0
        private IntPtr CallNativeObjectMethod(string methodName, string methodSig, object[] args)
        {
            var jargs       = AndroidJNIHelper.CreateJNIArgArray(args);
            var methodID    = AndroidJNI.GetStaticMethodID(BugsnagNativeInterface, methodName, methodSig);
            var nativeValue = AndroidJNI.CallStaticObjectMethod(BugsnagNativeInterface, methodID, jargs);

            AndroidJNIHelper.DeleteJNIArgArray(args, jargs);
            return(nativeValue);
        }
 public static IntPtr CallStaticObjectMethod(IntPtr clazz, IntPtr methodId, jvalue[] args)
 {
     try {
         return(AndroidJNI.CallStaticObjectMethod(clazz, methodId, args));
     }
     finally {
         CheckException();
     }
 }
 internal void DoFetchToken(Action callback)
 {
     //IL_002b: Unknown result type (might be due to invalid IL or missing references)
     //IL_0030: Expected O, but got Unknown
     object[] array  = new object[9];
     jvalue[] array2 = AndroidJNIHelper.CreateJNIArgArray(array);
     try
     {
         AndroidJavaClass val = new AndroidJavaClass("com.google.games.bridge.TokenFragment");
         try
         {
             AndroidJavaObject activity = GetActivity();
             try
             {
                 IntPtr staticMethodID = AndroidJNI.GetStaticMethodID(val.GetRawClass(), "fetchToken", "(Landroid/app/Activity;ZZZLjava/lang/String;Z[Ljava/lang/String;ZLjava/lang/String;)Lcom/google/android/gms/common/api/PendingResult;");
                 array2[0].l = activity.GetRawObject();
                 array2[1].z = requestAuthCode;
                 array2[2].z = requestEmail;
                 array2[3].z = requestIdToken;
                 array2[4].l = AndroidJNI.NewStringUTF(webClientId);
                 array2[5].z = forceRefresh;
                 array2[6].l = AndroidJNIHelper.ConvertToJNIArray((Array)oauthScopes.ToArray());
                 array2[7].z = hidePopups;
                 array2[8].l = AndroidJNI.NewStringUTF(accountName);
                 IntPtr ptr = AndroidJNI.CallStaticObjectMethod(val.GetRawClass(), staticMethodID, array2);
                 PendingResult <TokenResult> pendingResult = new PendingResult <TokenResult>(ptr);
                 pendingResult.setResultCallback(new TokenResultCallback(delegate(int rc, string authCode, string email, string idToken)
                 {
                     this.authCode = authCode;
                     this.email    = email;
                     this.idToken  = idToken;
                     callback();
                 }));
             }
             finally
             {
                 ((IDisposable)activity)?.Dispose();
             }
         }
         finally
         {
             ((IDisposable)val)?.Dispose();
         }
     }
     catch (Exception ex)
     {
         Logger.e("Exception launching token request: " + ex.Message);
         Logger.e(ex.ToString());
     }
     finally
     {
         AndroidJNIHelper.DeleteJNIArgArray(array, array2);
     }
 }
예제 #24
0
        public static string getMemStr(string tag)
        {
            IntPtr clazz          = AndroidJNI.FindClass("com/tencent/msdk/u3d/DebugMemInfo");
            IntPtr staticMethodID = AndroidJNI.GetStaticMethodID(clazz, "getmem_result", "(Ljava/lang/String;)[B");

            jvalue[] array = new jvalue[1];
            array[0].l = AndroidJNI.NewStringUTF(tag);
            IntPtr array2 = AndroidJNI.CallStaticObjectMethod(clazz, staticMethodID, array);

            byte[] array3 = AndroidJNI.FromByteArray(array2);
            return(Encoding.get_Default().GetString(array3));
        }
        internal void DoFetchToken(bool silent, Action <int> callback)
        {
            object[] objectArray = new object[10];
            jvalue[] jArgs       = AndroidJNIHelper.CreateJNIArgArray(objectArray);

            try
            {
                using (var bridgeClass = new AndroidJavaClass(TokenFragmentClass))
                {
                    using (var currentActivity = GetActivity())
                    {
                        // Unity no longer supports constructing an AndroidJavaObject using an IntPtr,
                        // so I have to manually munge with JNI here.
                        IntPtr methodId = AndroidJNI.GetStaticMethodID(bridgeClass.GetRawClass(),
                                                                       FetchTokenMethod,
                                                                       FetchTokenSignature);
                        jArgs[0].l = currentActivity.GetRawObject();
                        jArgs[1].z = silent;
                        jArgs[2].z = requestAuthCode;
                        jArgs[3].z = requestEmail;
                        jArgs[4].z = requestIdToken;
                        jArgs[5].l = AndroidJNI.NewStringUTF(webClientId);
                        jArgs[6].z = forceRefresh;
                        jArgs[7].l = AndroidJNIHelper.ConvertToJNIArray(oauthScopes.ToArray());
                        jArgs[8].z = hidePopups;
                        jArgs[9].l = AndroidJNI.NewStringUTF(accountName);

                        IntPtr ptr =
                            AndroidJNI.CallStaticObjectMethod(bridgeClass.GetRawClass(), methodId, jArgs);

                        PendingResult <TokenResult> pr = new PendingResult <TokenResult>(ptr);
                        pr.setResultCallback(new TokenResultCallback((rc, authCode, email, idToken) =>
                        {
                            this.authCode = authCode;
                            this.email    = email;
                            this.idToken  = idToken;
                            callback(rc);
                        }));
                    }
                }
            }
            catch (Exception e)
            {
                OurUtils.Logger.e("Exception launching token request: " + e.Message);
                OurUtils.Logger.e(e.ToString());
            }
            finally
            {
                AndroidJNIHelper.DeleteJNIArgArray(objectArray, jArgs);
            }
        }
예제 #26
0
        /// <summary>
        /// Gets all secondary storages and return only available ones.
        /// </summary>
        public static List <string> GetAvailableSecondaryStorages()
        {
            List <string> storages = new List <string> ();

#if !IGNORE_ANDROID_SCREENSHOT
            try {
                // Get methods
                AndroidJavaClass  classPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
                AndroidJavaObject objActivity = classPlayer.GetStatic <AndroidJavaObject> ("currentActivity");
                IntPtr            getExternalMediaDirsMethod = AndroidJNI.GetMethodID(objActivity.GetRawClass(), "getExternalMediaDirs", "()[Ljava/io/File;");
                //				IntPtr obj_context = AndroidJNI.FindClass ("android/content/ContextWrapper");
                //				IntPtr getExternalMediaDirsMethod = AndroidJNIHelper.GetMethodID (obj_context, "getExternalMediaDirs", "()[Ljava/io/File;");

                // Get files array
                IntPtr filesPtr = AndroidJNI.CallObjectMethod(objActivity.GetRawObject(), getExternalMediaDirsMethod, new jvalue[0]);

                // Get files from array
                IntPtr[] files = AndroidJNI.FromObjectArray(filesPtr);

                // Parse files
                for (int i = 0; i < files.Length; ++i)
                {
                    // Get file path
                    IntPtr getPathMethod = AndroidJNI.GetMethodID(AndroidJNI.GetObjectClass(files [i]), "getPath", "()Ljava/lang/String;");
                    IntPtr pathPtr       = AndroidJNI.CallObjectMethod(files [i], getPathMethod, new jvalue[] { });

                    string path = AndroidJNI.GetStringUTFChars(pathPtr);
                    AndroidJNI.DeleteLocalRef(pathPtr);

                    // Check path is available
                    AndroidJavaClass environment = new AndroidJavaClass("android.os.Environment");
                    IntPtr           getExternalStorageStateMethod = AndroidJNI.GetStaticMethodID(environment.GetRawClass(), "getExternalStorageState", "(Ljava/io/File;)Ljava/lang/String;");
                    jvalue[]         args = new jvalue[1];
                    args [0].l = files [i];
                    IntPtr statePtr = AndroidJNI.CallStaticObjectMethod(environment.GetRawClass(), getExternalStorageStateMethod, args);
                    string state    = AndroidJNI.GetStringUTFChars(statePtr);
                    AndroidJNI.DeleteLocalRef(statePtr);

                    if (state == "mounted")
                    {
                        storages.Add(path);
                    }
                }
            } catch (System.Exception e) {
                Debug.LogError("AndroidUtils: Error getting secondary external storage directory: " + e.Message);
            }
#endif

            return(storages);
        }
예제 #27
0
        private IntPtr AndroidJNISafeCallStaticObjectMethod(IntPtr clazz, IntPtr methodID, jvalue[] args)
        {
            IntPtr result;

            try
            {
                result = AndroidJNI.CallStaticObjectMethod(clazz, methodID, args);
            }
            finally
            {
                AndroidJNISafeCheckException();
            }
            return(result);
        }
 internal static void FetchToken(bool fetchAuthCode, bool fetchEmail, bool fetchIdToken, string webClientId, bool forceRefresh, Action <int, string, string, string> callback)
 {
     //IL_0013: Unknown result type (might be due to invalid IL or missing references)
     //IL_0018: Expected O, but got Unknown
     object[] array  = new object[7];
     jvalue[] array2 = AndroidJNIHelper.CreateJNIArgArray(array);
     try
     {
         AndroidJavaClass val = new AndroidJavaClass("com.google.games.bridge.TokenFragment");
         try
         {
             AndroidJavaObject activity = GetActivity();
             try
             {
                 IntPtr staticMethodID = AndroidJNI.GetStaticMethodID(val.GetRawClass(), "fetchToken", "(Landroid/app/Activity;ZZZLjava/lang/String;Z[Ljava/lang/String;ZLjava/lang/String;)Lcom/google/android/gms/common/api/PendingResult;");
                 array2[0].l = activity.GetRawObject();
                 array2[1].z = fetchAuthCode;
                 array2[2].z = fetchEmail;
                 array2[3].z = fetchIdToken;
                 array2[4].l = AndroidJNI.NewStringUTF(webClientId);
                 array2[5].z = forceRefresh;
                 IntPtr ptr = AndroidJNI.CallStaticObjectMethod(val.GetRawClass(), staticMethodID, array2);
                 PendingResult <TokenResult> pendingResult = new PendingResult <TokenResult>(ptr);
                 pendingResult.setResultCallback(new TokenResultCallback(callback));
             }
             finally
             {
                 ((IDisposable)activity)?.Dispose();
             }
         }
         finally
         {
             ((IDisposable)val)?.Dispose();
         }
     }
     catch (Exception ex)
     {
         Logger.e("Exception launching token request: " + ex.Message);
         Logger.e(ex.ToString());
     }
     finally
     {
         AndroidJNIHelper.DeleteJNIArgArray(array, array2);
     }
 }
예제 #29
0
        public static string GetPrimaryStorage()
        {
            try {
                AndroidJavaClass environment = new AndroidJavaClass("android.os.Environment");
                IntPtr           getExternalStorageDirectoryMethod = AndroidJNI.GetStaticMethodID(environment.GetRawClass(), "getExternalStorageDirectory", "()Ljava/io/File;");
                IntPtr           filePtr       = AndroidJNI.CallStaticObjectMethod(environment.GetRawClass(), getExternalStorageDirectoryMethod, new jvalue[] { });
                IntPtr           getPathMethod = AndroidJNI.GetMethodID(AndroidJNI.GetObjectClass(filePtr), "getPath", "()Ljava/lang/String;");
                IntPtr           pathPtr       = AndroidJNI.CallObjectMethod(filePtr, getPathMethod, new jvalue[] { });
                string           path          = AndroidJNI.GetStringUTFChars(pathPtr);
                AndroidJNI.DeleteLocalRef(filePtr);
                AndroidJNI.DeleteLocalRef(pathPtr);

                return(path);
            } catch (System.Exception e) {
                Debug.LogError("AndroidUtils: Error getting primary external storage directory: " + e.Message);
            }
            return("");
        }
예제 #30
0
        private static string GetAndroidExternalStoragePublicDirectory(string type)
        {
            AndroidJavaClass jc          = new AndroidJavaClass("android.os.Environment");
            IntPtr           typeFieldId = AndroidJNI.GetStaticFieldID(jc.GetRawClass(), type, "Ljava/lang/String;");
            string           typeField   = AndroidJNI.GetStaticStringField(jc.GetRawClass(), typeFieldId);
            IntPtr           getExternalStorageDirectoryMethod = AndroidJNI.GetStaticMethodID(jc.GetRawClass(), "getExternalStoragePublicDirectory", "(Ljava/lang/String;)Ljava/io/File;");

            jvalue[] args          = AndroidJNIHelper.CreateJNIArgArray(new object[] { typeField });
            IntPtr   file          = AndroidJNI.CallStaticObjectMethod(jc.GetRawClass(), getExternalStorageDirectoryMethod, args);
            IntPtr   getPathMethod = AndroidJNI.GetMethodID(AndroidJNI.GetObjectClass(file), "getPath", "()Ljava/lang/String;");
            IntPtr   path          = AndroidJNI.CallObjectMethod(file, getPathMethod, new jvalue[] { });
            string   pathString    = AndroidJNI.GetStringUTFChars(path);

            AndroidJNI.DeleteLocalRef(file);
            AndroidJNI.DeleteLocalRef(path);

            return(pathString);
        }