コード例 #1
0
 protected virtual void Dispose(bool disposing)
 {
     if (!_disposedValue)
     {
         if (disposing)
         {
             Proxy?.Dispose();
         }
         _disposedValue = true;
     }
 }
コード例 #2
0
    void androidVibrate(int timeInMiliSec)
    {
        if (Application.platform != RuntimePlatform.Android)
        {
            return;
        }
        AndroidJavaClass  unity           = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject ca              = unity.GetStatic <AndroidJavaObject>("currentActivity");
        AndroidJavaClass  vibratorClass   = new AndroidJavaClass("android.os.Vibrator");
        AndroidJavaObject vibratorService = ca.Call <AndroidJavaObject>("getSystemService", "vibrator");

        vibratorService.Call("vibrate", (long)timeInMiliSec);
        unity.Dispose();
        ca.Dispose();
        vibratorClass.Dispose();
        vibratorService.Dispose();
    }
コード例 #3
0
    //Android specific methods

    public string[] GetPushHistory()
    {
#if UNITY_ANDROID && !UNITY_EDITOR
        AndroidJavaObject history = pushwoosh.Call <AndroidJavaObject>("getPushHistory");
        if (history.GetRawObject().ToInt32() == 0)
        {
            return(new string[0]);
        }

        string[] result = AndroidJNIHelper.ConvertFromJNIArray <string[]>(history.GetRawObject());
        history.Dispose();

        return(result);
#else
        return(new string[0]);
#endif
    }
コード例 #4
0
    private static byte[] LoadFileFromStreamingAssets(string file)
    {
#if UNITY_EDITOR || UNITY_STANDALONE
        string assembly = Path.Combine(Application.streamingAssetsPath, file);
        if (File.Exists(assembly))
        {
            var bytes = File.ReadAllBytes(assembly);
            return(bytes);
        }
#elif UNITY_ANDROID
        AndroidJavaClass  androidJavaClass    = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject androidJavaActivity = null;
        AndroidJavaObject assetManager        = null;
        AndroidJavaObject inputStream         = null;
        if (androidJavaClass != null)
        {
            androidJavaActivity = androidJavaClass.GetStatic <AndroidJavaObject>("currentActivity");
        }
        if (androidJavaActivity != null)
        {
            assetManager = androidJavaActivity.Call <AndroidJavaObject>("getAssets");
        }
        if (assetManager != null)
        {
            inputStream = assetManager.Call <AndroidJavaObject>("open", file);
        }
        if (inputStream != null)
        {
            int           available    = inputStream.Call <int>("available");
            System.IntPtr buffer       = AndroidJNI.NewByteArray(available);
            System.IntPtr javaClass    = AndroidJNI.FindClass("java/io/InputStream");
            System.IntPtr javaMethodID = AndroidJNIHelper.GetMethodID(javaClass, "read", "([B)I");
            int           read         = AndroidJNI.CallIntMethod(inputStream.GetRawObject(), javaMethodID,
                                                                  new[] { new jvalue()
                                                                          {
                                                                              l = buffer
                                                                          } });
            byte[] bytes = AndroidJNI.FromByteArray(buffer);
            AndroidJNI.DeleteLocalRef(buffer);
            inputStream.Call("close");
            inputStream.Dispose();
            return(bytes);
        }
#endif
        return(null);
    }
コード例 #5
0
        public override void Dispose()
        {
            Debug.LogError("DISPOSE");
            if (m_Video != null)
            {
                m_Video.Call("Deinitialise");

                m_Video.Dispose();
                m_Video = null;
            }

            if (m_Texture != null)
            {
                Texture2D.Destroy(m_Texture);
                m_Texture = null;
            }
        }
コード例 #6
0
        /* TEST
         * public byte[] test (byte[] x)
         * {
         *
         *      if (!PluginReady)
         *              return new byte[]{};
         *
         *      return ajc.Call<byte[]> ("TEST", x);
         * }
         */


        //THIS METHOD SHOULD BE CALLED AFTER EVERYTHING RELATED TO BLUETOOTH NEEDS TO BE ENDED
        public void OnDestroy()
        {
            if (PluginReady)
            {
                ajc.Call(ON_DESTROY);
            }

            try {
                if (ajc != null)
                {
                    ajc.Dispose();
                }
            } catch (UnityException) {
            }

            instance = null;            //This will dispose this instance. And will create a new one if needed next time.
        }
コード例 #7
0
    /// <summary>
    /// Constructor.
    /// </summary>
    public GoogleDrive()
    {
#if !UNITY_EDITOR && UNITY_ANDROID
        pluginClass = new AndroidJavaClass("com.studio272.googledriveplugin.GoogleDrivePlugin");

        // Set Unity activity.
        {
            AndroidJavaClass  unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject unityActivity    = unityPlayerClass.GetStatic <AndroidJavaObject>("currentActivity");

            pluginClass.CallStatic("setUnityActivity", new object[] { unityActivity });

            unityActivity.Dispose();
            unityPlayerClass.Dispose();
        }
#elif !UNITY_EDITOR && UNITY_IPHONE
#endif
    }
コード例 #8
0
ファイル: AndroidUtils.cs プロジェクト: ping203/WebGameNew
 public static int PhoneCount()
 {
     if (IsLoadDualSim)
     {
         return(SimCount);
     }
             #if UNITY_ANDROID && !UNITY_EDITOR
     AndroidJavaClass  unityClass  = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
     AndroidJavaObject activity    = unityClass.GetStatic <AndroidJavaObject>("currentActivity");
     AndroidJavaClass  deviceUtils = new AndroidJavaClass("deviceutils.sboy.com.androiddeviceutils.DeviceUtils");
     SimCount = deviceUtils.CallStatic <int>("GetPhoneCount", activity);
     deviceUtils.Dispose();
     activity.Dispose();
     unityClass.Dispose();
     IsLoadDualSim = true;
             #endif
     return(SimCount);
 }
コード例 #9
0
    // 指定したintentを開く
    public static void CallIntent(string Action = "android.settings.LOCATION_SOURCE_SETTINGS")
    {
        // Find the UnityPlayer and get the static current activity
        AndroidJavaClass  cUnityPlayer     = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject oCurrentActivity = cUnityPlayer.GetStatic <AndroidJavaObject>("currentActivity");

        // Get defenitions of Intent and it's constructor.
        AndroidJavaObject oIntent = new AndroidJavaObject("android.content.Intent");

        oIntent.Call <AndroidJavaObject>("setAction", Action);

        // Start the activity!
        oCurrentActivity.Call("startActivity", oIntent);

        //Dispose them. Not sure if I need to do it or not...
        oIntent.Dispose();
        oCurrentActivity.Dispose();
    }
コード例 #10
0
        public static List <T> FromJavaList <T>(this AndroidJavaObject javaList)
        {
            if (javaList == null || javaList.IsJavaNull())
            {
                return(new List <T>());
            }

            int size = javaList.CallInt("size");
            var list = new List <T>(size);

            for (int i = 0; i < size; i++)
            {
                list.Add(javaList.Call <T>("get", i));
            }

            javaList.Dispose();
            return(list);
        }
コード例 #11
0
 public static void PlaySessionSendEvent(string key, float value, params string[] tags)
 {
     using (AndroidJavaClass javaClass = new AndroidJavaClass("com.unity.unitysocial.PlaySession"))
     {
         AndroidJavaObject hashMap = new AndroidJavaObject("java.util.HashMap");
         IntPtr            put     = AndroidJNIHelper.GetMethodID(hashMap.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
         object[]          args    = new object[2];
         AndroidJavaObject k       = new AndroidJavaObject("java.lang.String", key);
         AndroidJavaObject v       = new AndroidJavaObject("java.lang.Float", value);
         args[0] = k;
         args[1] = v;
         AndroidJNI.CallObjectMethod(hashMap.GetRawObject(), put, AndroidJNIHelper.CreateJNIArgArray(args));
         k.Dispose();
         v.Dispose();
         javaClass.CallStatic("sendEvent", hashMap);
         hashMap.Dispose();
     }
 }
コード例 #12
0
        public static bool StopRecording()
        {
            if (AGUtils.IsNotAndroid())
            {
                return(false);
            }

            if (_mediaRecorder == null)
            {
                return(false);
            }

            _mediaRecorder.Call("stop");
            _mediaRecorder.Call("release");
            _mediaRecorder.Dispose();
            _mediaRecorder = null;
            return(true);
        }
コード例 #13
0
ファイル: AndroidUtils.cs プロジェクト: ping203/WebGameNew
    public static string GetNetworkOperatorName_SIM()
    {
        if (!string.IsNullOrEmpty(_NetworkOperatorName_SIM1))
        {
            return(_NetworkOperatorName_SIM1);
        }
#if UNITY_ANDROID && !UNITY_EDITOR
        AndroidJavaClass  unityClass  = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject activity    = unityClass.GetStatic <AndroidJavaObject>("currentActivity");
        AndroidJavaClass  deviceUtils = new AndroidJavaClass("deviceutils.sboy.com.androiddeviceutils.DeviceUtils");
        _NetworkOperatorName_SIM1 = deviceUtils.CallStatic <string>("GetNetworkOperatorName", activity);

        deviceUtils.Dispose();
        activity.Dispose();
        unityClass.Dispose();
#endif
        return(_NetworkOperatorName_SIM1);
    }
コード例 #14
0
    /**
     * ============================================= Initializers =====================================================
     */

    /**
     * <summary>Initializer of handlers that ensure effectiveness of Android/Unity integration/communication.</summary>
     */
    private void Init()
    {
        // Attach current thread to a Java virtual machine.
        AndroidJNI.AttachCurrentThread();

        // Creation of an instance of the Android-Java connection class.
        activityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");

        // Establishing the context of the Android activity.
        activityContext = activityClass.GetStatic <AndroidJavaObject>("currentActivity");

        // Definition of the interface between Unity and Android, i.e., an instance to the PLUXApiPlugin
        // class.
        AndroidJavaClass pluginClass = new AndroidJavaClass("info.plux.api.PLUXApiPlugin");

        // Initializing device.
        InitDevice();

        // Check if an instance of the pluginClass was previously created.
        if (pluginClass != null)
        {
            androidSensorsClass = pluginClass.CallStatic <AndroidJavaObject> ("getInstance");

            // Start Unity/Android communication through sequential calls.
            if (androidSensorsClass != null)
            {
                androidSensorsClass.Call("setContext", activityContext);
                androidSensorsClass.Call("setGameObjectName", this.gameObject.name);
                androidSensorsClass.Call("restart");
                androidSensorsClass.Call("init");
            }
        }

        // Object destruction.
        if (activityClass != null)
        {
            activityClass.Dispose();
        }

        if (activityContext != null)
        {
            activityContext.Dispose();
        }
    }
コード例 #15
0
        public static List <T> FromJavaIterable <T>(this AndroidJavaObject javaIterable)
        {
            if (javaIterable.IsJavaNull())
            {
                return(new List <T>());
            }

            var size     = javaIterable.CallInt("size");
            var iterator = javaIterable.CallAJO("iterator");
            var list     = new List <T>(size);

            while (iterator.CallBool("hasNext"))
            {
                list.Add(iterator.Call <T>("next"));
            }

            javaIterable.Dispose();
            return(list);
        }
コード例 #16
0
        public static void OpenActivity(string packageName, string className, bool asNewTask)
        {
#if !UNITY_EDITOR && UNITY_ANDROID
            AndroidJavaClass  cUnityPlayer     = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject oCurrentActivity = cUnityPlayer.GetStatic <AndroidJavaObject>("currentActivity");
            AndroidJavaObject oIntent          = new AndroidJavaObject("android.content.Intent");

            oIntent.Call <AndroidJavaObject>("setAction", "android.intent.action.VIEW");
            if (asNewTask)
            {
                oIntent.Call <AndroidJavaObject>("setFlags", 0x10000000); // FLAG_ACTIVITY_NEW_TASK
            }
            oIntent.Call <AndroidJavaObject>("setClassName", packageName, packageName + "." + className);
            oCurrentActivity.Call("startActivity", oIntent);

            oIntent.Dispose();
            oCurrentActivity.Dispose();
#endif
        }
コード例 #17
0
        public static List <T> FromJavaList <T>(this AndroidJavaObject javaList, Func <AndroidJavaObject, T> converter)
        {
            if (javaList.IsJavaNull())
            {
                return(new List <T>());
            }

            int size = javaList.CallInt("size");
            var list = new List <T>(size);

            for (int i = 0; i < size; i++)
            {
                var listItem = converter(javaList.CallAJO("get", i));
                list.Add(listItem);
            }

            javaList.Dispose();
            return(list);
        }
コード例 #18
0
    private void OnDestroy()
    {
#pragma warning disable CS0162
        if (isLogging)
        {
            Debug.Log(TAG + "OnDestroy");
        }
#pragma warning restore CS0162
        // Garbage native plugin
#if UNITY_ANDROID && !UNITY_EDITOR
        if (scanPlugin != null)
        {
            scanPlugin.Dispose();
        }
#elif UNITY_IOS && !UNITY_EDITOR
        Dispose();
#elif UNITY_STANDALONE_OSX || UNITY_EDITOR
#endif
    }
コード例 #19
0
 public void CallRunnable(AndroidJavaObject obj, string methodName, bool methodIsStatic, System.Action action)
 {
     if (action != null)
     {
         if (methodIsStatic)
         {
             obj.CallStatic(methodName, new AndroidJavaRunnable(() => {
                 action();
             }));
         }
         else
         {
             obj.Call(methodName, new AndroidJavaRunnable(() => {
                 action();
             }));
         }
     }
     obj.Dispose();
 }
コード例 #20
0
    public void Send()
    {
        // Find the UnityPlayer and get the static current activity
        AndroidJavaClass  cUnityPlayer     = getStaticNativeClass();
        AndroidJavaObject oCurrentActivity = cUnityPlayer.GetStatic <AndroidJavaObject> ("currentActivity");

        // Get defenitions of Intent and it's constructor.
        AndroidJavaObject oIntent = new AndroidJavaObject("android.content.Intent");

        // Call some methods
        oIntent.Call <AndroidJavaObject> ("setAction", "android.intent.action.SEND");
        oIntent.Call <AndroidJavaObject> ("setType", "text/plain");
        oIntent.Call <AndroidJavaObject> ("putExtra", "android.intent.extra.TITLE", "Hello");
        // Start the activity!
        oCurrentActivity.Call("startActivity", oIntent);
        //Dispose them. Not sure if I need to do it or not...
        oIntent.Dispose();
        oCurrentActivity.Dispose();
    }
コード例 #21
0
ファイル: SafeGame.cs プロジェクト: deb2610/PAINTRAIN
    // Unity by default doesn't do this, so we're gonna do it ourselves
    void Vibrate(float duration)
    {
        // This will only work on Android
        if (Application.platform != RuntimePlatform.Android)
        {
            return;
        }

        AndroidJavaClass  unity           = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject ca              = unity.GetStatic <AndroidJavaObject>("currentActivity");
        AndroidJavaClass  vibratorClass   = new AndroidJavaClass("android.os.Vibrator");
        AndroidJavaObject vibratorService = ca.Call <AndroidJavaObject>("getSystemService", "vibrator");

        vibratorService.Call("vibrate", (long)(duration * 1000));
        unity.Dispose();
        ca.Dispose();
        vibratorClass.Dispose();
        vibratorService.Dispose();
    }
コード例 #22
0
ファイル: AndroidActivity.cs プロジェクト: mulova/comunity
 public void Dispose()
 {
     if (Application.isEditor)
     {
         return;
     }
     activityCls.Dispose();
     activityInst.Dispose();
     foreach (KeyValuePair <string, AndroidJavaClass> pair in classes)
     {
         pair.Value.Dispose();
     }
     classes.Clear();
     foreach (KeyValuePair <string, AndroidJavaObject> pair in objects)
     {
         pair.Value.Dispose();
     }
     objects.Clear();
 }
コード例 #23
0
    private static void _sendLtv(int cvId, string adId)
    {
        AndroidJavaObject ltv = new AndroidJavaObject(ltvClass, currentActivity, ad);

        foreach (DictionaryEntry de in p)
        {
            ltv.Call("addParam", de.Key, de.Value);
        }
        if (adId == null)
        {
            ltv.Call("sendLtvConversionUnity", cvId);
        }
        else
        {
            ltv.Call("sendLtvConversionUnity", cvId, adId);
        }
        ltv.Dispose();
        p = new Hashtable();
    }
コード例 #24
0
 private static void Dispose()
 {
     worksheet.Dispose();
     worksheet = null;
     workbook.Dispose();
     workbook = null;
     patriarch.Dispose();
     patriarch = null;
     foreach (var style in styles)
     {
         style.Dispose();
     }
     styles = new List <AndroidJavaObject>();
     foreach (var data in dataTable)
     {
         data.Dispose();
     }
     dataTable = null;
 }
コード例 #25
0
    public void callUrlScheme(string appScheme, string appID)
    {
        Guid myGUID = Guid.NewGuid();

        randomMessage = myGUID.ToString();         //generate random msg for the apps to sign and verify address

        bool fail = false;

                        #if UNITY_IPHONE
        Application.OpenURL(appScheme + "://x-callback-url/getaddress?msg=" + randomMessage + "&x-success=" + urlscheme);
                        #endif
                        #if UNITY_ANDROID
        AndroidJavaClass  up             = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject ca             = up.GetStatic <AndroidJavaObject> ("currentActivity");
        AndroidJavaObject packageManager = ca.Call <AndroidJavaObject> ("getPackageManager");
        AndroidJavaObject launchIntent   = null;

        launchIntent = packageManager.Call <AndroidJavaObject> ("getLaunchIntentForPackage", appID);
        try {
            Debug.Log("launching intent");
            launchIntent.Call <AndroidJavaObject> ("putExtra", "source", "x-callback-url/getaddress?x-success=" + urlscheme + "&msg=" + randomMessage);
            Debug.Log(launchIntent.ToString());
        } catch (System.Exception e) {
            fail = true;
        }

        if (fail)
        {
            Debug.Log("app not found");
        }
        else
        {
            Debug.Log("Launch activity");

            ca.Call("startActivity", launchIntent);
        }
        up.Dispose();
        ca.Dispose();
        packageManager.Dispose();
        launchIntent.Dispose();
                        #endif
    }
コード例 #26
0
    private void startPPTXAplication()
    {
        bool              fail            = false;
        string            bundleId        = "com.petar.pptx";
        AndroidJavaClass  unityPlayer     = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject currentActivity = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity");
        AndroidJavaObject packageManager  = currentActivity.Call <AndroidJavaObject>("getPackageManager");

        AndroidJavaObject launchIntent = null;

        try
        {
            launchIntent = packageManager.Call <AndroidJavaObject>("getLaunchIntentForPackage", bundleId);
            if (launchIntent == null)
            {
                fail = true;
            }
        }
        catch (System.Exception e)
        {
            fail = true;
        }

        if (fail)
        {
            InstalPPTXViewerAPK();
        }
        else
        {
            string apkPath = Application.persistentDataPath + "/PPTXViewer.apk";
            if (File.Exists(apkPath))
            {
                File.Delete(apkPath);
            }
            currentActivity.Call("startActivity", launchIntent);
        }

        unityPlayer.Dispose();
        currentActivity.Dispose();
        packageManager.Dispose();
        launchIntent.Dispose();
    }
コード例 #27
0
ファイル: DetailBehaviour.cs プロジェクト: YeYufei/ARTeam
    public void OpenMapOnClick()
    {
        if (string.IsNullOrEmpty(addressURL.text) || !addressURL.text.StartsWith("http"))
        {
            return;
        }
        bool              fail           = false;
        AndroidJavaClass  up             = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject ca             = up.GetStatic <AndroidJavaObject>("currentActivity");
        AndroidJavaObject packageManager = ca.Call <AndroidJavaObject>("getPackageManager");

        AndroidJavaObject launchIntent = null;

        try
        {
            launchIntent = packageManager.Call <AndroidJavaObject>("getLaunchIntentForPackage", "com.google.android.apps.maps");
        }
        catch (Exception e)
        {
            Console.WriteLine(e.StackTrace);
            fail = true;
        }

        if (fail)
        {   //open app in store
            Application.OpenURL("https://google.com");
        }
        else
        {
            //open the app
            //Application.OpenURL("https://goo.gl/maps/sL2Tug3N5oytfJvR7");
            if (!string.IsNullOrEmpty(addressURL.text))
            {
                Application.OpenURL(addressURL.text);
            }
        }

        up.Dispose();
        ca.Dispose();
        packageManager.Dispose();
        launchIntent.Dispose();
    }
コード例 #28
0
ファイル: AGPermissions.cs プロジェクト: 1samuel411/HackIRL
            // ReSharper disable once InconsistentNaming
            // ReSharper disable once UnusedMember.Local
            void onRequestPermissionsResults(AndroidJavaObject results)
            {
                int size           = results.CallInt("size");
                var requestResults = new PermissionRequestResult[size];

                for (int i = 0; i < size; i++)
                {
                    var    resultAJO  = results.CallAJO("get", i);
                    string permission = resultAJO.CallStr("getPermission");
                    bool   shouldShowRequestPermissionRationale = resultAJO.CallBool("isShouldShowRequestPermissionRationale");
                    var    status = (PermissionStatus)resultAJO.CallInt("getResult");
                    requestResults[i] = new PermissionRequestResult(permission, shouldShowRequestPermissionRationale, status);
                }

                if (_onResult != null)
                {
                    GoodiesSceneHelper.Queue(() => _onResult(requestResults));
                }
                results.Dispose();
            }
コード例 #29
0
ファイル: AGFlashLight.cs プロジェクト: 1samuel411/HackIRL
        /// <summary>
        /// Turns off the camera flashlight
        /// </summary>
        public static void Disable()
        {
            if (AGUtils.IsNotAndroidCheck())
            {
                return;
            }

            if (_camera == null)
            {
                return;
            }

            AGUtils.RunOnUiThread(() =>
            {
                _camera.Call("stopPreview");
                _camera.Call("release");
                _camera.Dispose();
                _camera = null;
            });
        }
コード例 #30
0
    public void launchApp(AppObject appobj)
    {
        bool fail = false;
        //string bundleId = packageName; // your target bundle id
        AndroidJavaClass  up             = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject ca             = up.GetStatic <AndroidJavaObject>("currentActivity");
        AndroidJavaObject packageManager = ca.Call <AndroidJavaObject>("getPackageManager");

        AndroidJavaObject launchIntent = null;

        try
        {
            launchIntent = appobj.Link; //packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage", bundleId);
        }
        catch (System.Exception e)
        {
            text.text  = e.Message;
            text.text += appobj.Name;
            fail       = true;
        }

        if (fail)
        { //open app in store
            //text.text = "Opening Google";
            //Application.OpenURL("https://google.com");
            if (appobj == null)
            {
                text.text = "No app object";
            }
        }
        else //open the app
        {
            text.text = "Launching";
            ca.Call("startActivity", launchIntent);
        }

        up.Dispose();
        ca.Dispose();
        packageManager.Dispose();
        launchIntent.Dispose();
    }