Ejemplo n.º 1
0
        public BluetoothLeDevice Startup(bool asCentral, Action action, Action <string> errorAction, Action <string> stateUpdateAction, Action <string, string> rssiUpdateAction)
        {
            bluetoothDevice = null;


            if (GameObject.Find("BleBridge") == null)
            {
                GameObject bleBridgeObj = new GameObject("BleBridge");
                bluetoothDevice = bleBridgeObj.AddComponent <BluetoothLeDevice> ();

                if (bluetoothDevice != null)
                {
                    bluetoothDevice.isLowerCaseUUID = true;

                    bluetoothDevice.StartupAction       = action;
                    bluetoothDevice.ErrorAction         = errorAction;
                    bluetoothDevice.StateUpdateAction   = stateUpdateAction;
                    bluetoothDevice.DidUpdateRssiAction = rssiUpdateAction;
                }
            }

            // First, obtain the current activity context
            using (var actClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
                playerActivityContext = actClass.GetStatic <AndroidJavaObject>("currentActivity");
            }

            // Pass the context to a newly instantiated TestUnityProxy object
            using (var pluginClass = new AndroidJavaClass("com.startechplus.unityblebridge.Bridge")) {
                if (pluginClass != null)
                {
                    bridge = pluginClass.CallStatic <AndroidJavaObject>("instance");
                    bridge.Call("setContext", playerActivityContext);
                    bridge.Call("startup", bluetoothDevice.gameObject.name, asCentral);
                }
                else
                {
                    Debug.Log("AndroidBleBridge: Error creating Android objects...");
                }
            }


            return(bluetoothDevice);
        }
Ejemplo n.º 2
0
        public BluetoothLeDevice Startup(bool asCentral, Action action, Action <string> errorAction, Action <string> stateUpdateAction, Action <string, string> rssiUpdateAction)
        {
            bluetoothDevice = null;

            if (GameObject.Find("BleBridge") == null)
            {
                GameObject bleBridgeObj = new GameObject("BleBridge");
                bluetoothDevice = bleBridgeObj.AddComponent <BluetoothLeDevice> ();

                if (bluetoothDevice != null)
                {
                    bluetoothDevice.StartupAction       = action;
                    bluetoothDevice.ErrorAction         = errorAction;
                    bluetoothDevice.StateUpdateAction   = stateUpdateAction;
                    bluetoothDevice.DidUpdateRssiAction = rssiUpdateAction;
                }
            }

            bluetoothDevice.OnStartup("Startup");
            bluetoothDevice.OnStateUpdate("Powered On");

            return(bluetoothDevice);
        }