Exemple #1
0
        public async Task <bool> ConnectToBand(TestMeViewModel b)
        {
            try
            {
                if (_client == null)
                {
                    //get all paired devices (we only care about the 1st)
                    IBandInfo[] devices = BandClientManager.Instance.GetPairedBands();
                    if (devices.Length == 0)
                    {
                        if (b != null)
                        {
                            b.IsConnected = false;
                        }
                        Activity activity = Droid.MainActivity.instance;
                        activity.RunOnUiThread(() =>
                        {
                            Toast.MakeText(Droid.MainActivity.context,
                                           "make sure your band is paired with this device and try again",
                                           ToastLength.Long).Show();
                        });
                        return(false);
                    }
                    _client = BandClientManager.Instance.Create(Droid.MainActivity.context, devices[0]);
                }
                else if (_client.ConnectionState == ConnectionState.Connected)
                {
                    if (b != null)
                    {
                        b.IsConnected = true;
                    }
                    return(true);
                }
                //connecting to device
                ConnectionState connectionState = await _client.ConnectTaskAsync();

                if (b != null)
                {
                    b.IsConnected = _client.IsConnected;
                }               //update TestMeViewModel
                InitSensors(b); //register sensors listeners
                return(_client.IsConnected);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
        }
Exemple #2
0
        protected async override void OnCreate(Bundle bundle)
        {
            // tests can be inside the main assembly
            AddTest(Assembly.GetExecutingAssembly());
            // or in any reference assemblies
            // AddTest (typeof (Your.Library.TestClass).Assembly);

            // Once you called base.OnCreate(), you cannot add more assemblies.
            base.OnCreate(bundle);

            IBandDeviceInfo[] pairedBands = BandClientManager.Instance.GetPairedBands();
            if (pairedBands.Length < 1)
            {
                Assert.Inconclusive("No Microsoft Bands available!");
            }
            IBandClient      bandClient = BandClientManager.Instance.Create(this, pairedBands[0]);
            ConnectionResult result     = await bandClient.ConnectTaskAsync();

            Assert.AreEqual(ConnectionResult.Ok, result);

            BandClient = bandClient;
        }