Last active
August 23, 2019 10:35
-
-
Save mattleibow/263c8db7cc3f7f2044c4 to your computer and use it in GitHub Desktop.
Connect to MS Band
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Windows Phone RT code | |
public void Connect(UInt16 maxConnectAttempts = 1) | |
{ | |
Guid guid = new Guid("{C742E1A2-6320-5ABC-9643-D206C677E580}"); | |
var device = RfcommDeviceService.FromIdAsync(this.associatedBand.Peer.Id).AsTask().Result.Device; | |
foreach (var current in device.RfcommServices) | |
{ | |
if (current.ServiceId.Uuid != guid) | |
{ | |
continue; | |
} | |
base.Connect(current, maxConnectAttempts); | |
base.CargoStream.ReadTimeout = 2147483647; | |
return; | |
} | |
throw new BandIOException(StoreResources.PushServiceNotFound); | |
} | |
// totally hacked/whipped up (nmot tested in any way) code for Store | |
public void Connect(UInt16 maxConnectAttempts = 1) | |
{ | |
Guid guid = new Guid("{C742E1A2-6320-5ABC-9643-D206C677E580}"); | |
var list = DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.FromUuid(guid))).AsTask().Result; | |
var hasDevice = list.Any(i => i.Id == this.associatedBand.Peer.Id); | |
if (hasDevice) | |
{ | |
var service = RfcommDeviceService.FromIdAsync(this.associatedBand.Peer.Id).AsTask().Result; | |
base.Connect(service, maxConnectAttempts); | |
base.CargoStream.ReadTimeout = 2147483647; | |
return; | |
} | |
throw new BandIOException(StoreResources.PushServiceNotFound); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment