我想通过Windows Phone的UWP应用中的Microsoft Band SDK将自定义图块添加到Microsoft Band。这是我的示例代码。尝试从UWP应用向Microsoft Band添加自定义图块
private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
try
{
// Get the list of Microsoft Bands paired to the phone.
var pairedBands = await BandClientManager.Instance.GetBandsAsync();
if (pairedBands.Length < 1)
{
Debug.WriteLine("This sample app requires a Microsoft Band paired to your device.Also make sure that you have the latest firmware installed on your Band, as provided by the latest Microsoft Health app.");
return;
}
// Connect to Microsoft Band.
using (var bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]))
{
// Create a Tile with a TextButton on it.
var myTileId = new Guid("12408A60-13EB-46C2-9D24-F14BF6A033C6");
var myTile = new BandTile(myTileId)
{
Name = "My Tile",
TileIcon = await LoadIcon("ms-appx:///Assets/SampleTileIconLarge.png"),
SmallIcon = await LoadIcon("ms-appx:///Assets/SampleTileIconSmall.png")
};
// Remove the Tile from the Band, if present. An application won't need to do this everytime it runs.
// But in case you modify this sample code and run it again, let's make sure to start fresh.
await bandClient.TileManager.RemoveTileAsync(myTileId);
// Create the Tile on the Band.
await bandClient.TileManager.AddTileAsync(myTile);
// Subscribe to Tile events.
}
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
private async Task<BandIcon> LoadIcon(string uri)
{
StorageFile imageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(uri));
using (IRandomAccessStream fileStream = await imageFile.OpenAsync(FileAccessMode.Read))
{
WriteableBitmap bitmap = new WriteableBitmap(1, 1);
await bitmap.SetSourceAsync(fileStream);
return bitmap.ToBandIcon();
}
}
如果我运行这段代码什么都没有发生。该应用连接到Microsoft Band,但无法添加磁贴。方法AddTileAsync(myTile);
返回false并且不会将图块添加到Microsoft Band。
如果我在Windows Phone 8.1应用程序中试用此代码,但它不适用于UWP应用程序。
任何想法?
更新 这里是sample app as download。也许这可以帮助。
你确定你尚未与最大的瓷砖填补你的乐队?顺便说一下,您正在测试哪个频段? –
正如@SvenBorden所说的,您可能想要检查您是否有能力添加带状图块。 –
斯文和詹姆斯你好,我也检查过我有乐队的能力。目前我有5个空插槽。我针对Microsoft Band 2开发了这个按钮。 –