我想通過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開發了這個按鈕。 –