私はMSDNチュートリアルで作成したこのデスクトップアプリケーションを持っています(リンクが見つかりません。そうでない場合はリンクします)。それが何をするか、それはあなたがウィンドウズ電話エミュレーターに接続するのに必要なチャンネルURLを入れることを可能にし、そしてアプリケーションを通してあなたはライブタイルアップデートを送ることができます:これはエミュレーター(リスナー)とサービスを送るサービスの両方のコードですデータ。:
MainApp-Emultor:
public MainPage()
{
HttpNotificationChannel pushChannel;
string channelName = "TileSampleChannel";
InitializeComponent();
pushChannel = HttpNotificationChannel.Find(channelName);
if (pushChannel == null)
{
pushChannel = new HttpNotificationChannel(channelName);
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
pushChannel.Open();
pushChannel.BindToShellTile();
}
else
{
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
MessageBox.Show(String.Format("Channel Uri is {0}",
pushChannel.ChannelUri.ToString()));
}
}
void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
{
Dispatcher.BeginInvoke(() =>
{
System.Diagnostics.Debug.WriteLine(e.ChannelUri.ToString());
//MessageBox.Show(String.Format("Channel Uri is {0}",
// e.ChannelUri.ToString()));
});
}
void PushChannel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e)
{
Dispatcher.BeginInvoke(() =>
MessageBox.Show(String.Format("A push notification {0} error occurred. {1} ({2}) {3}",
e.ErrorType, e.Message, e.ErrorCode, e.ErrorAdditionalData))
);
}
}
ここにサービスがあります:
protected void ButtonSendTile_Click(object sender, EventArgs e)
{
try
{
string NotifyURI = TextBoxUri.Text.ToString();
HttpWebRequest sendNotificationRequest = (HttpWebRequest)WebRequest.Create(NotifyURI);
sendNotificationRequest.Method = "POST";
//Create the toast message
string notificationData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<wp:Notification xmlns:wp=\"WPNotification\">" +
"<wp:Toast>" +
"<wp:Text1>WP8 TOAST</wp:Text1>" +
"<wp:Text2>" + TextBoxBackContent.Text + "</wp:Text2>" +
"</wp:Toast>" +
"</wp:Notification>";
// Create the tile message.
string tileMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<wp:Notification xmlns:wp=\"WPNotification\">" +
"<wp:Tile>" +
"<wp:BackgroundImage>" + TextBoxBackgroundImage.Text + "</wp:BackgroundImage>" +
"<wp:Count>" + TextBoxCount.Text + "</wp:Count>" +
"<wp:Title>" + TextBoxTitle.Text + "</wp:Title>" +
"<wp:BackBackgroundImage>" + TextBoxBackBackgroundImage.Text + "</wp:BackBackgroundImage>" +
"<wp:BackTitle>" + TextBoxBackTitle.Text + "</wp:BackTitle>" +
"<wp:BackContent>" + TextBoxBackContent.Text + "</wp:BackContent>" +
"</wp:Tile> " +
"</wp:Notification>";
byte[] notificationMessage = Encoding.Default.GetBytes(tileMessage);
sendNotificationRequest.ContentLength = notificationMessage.Length;
sendNotificationRequest.ContentType = "text/xml";
sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "token");
sendNotificationRequest.Headers.Add("X-NotificationClass", "1");
using (Stream requestStream = sendNotificationRequest.GetRequestStream())
{
requestStream.Write(notificationMessage, 0, notificationMessage.Length);
}
HttpWebResponse response = (HttpWebResponse)sendNotificationRequest.GetResponse();
string notificationStatus = response.Headers["X-NotificationStatus"];
string notificationChannelStatus = response.Headers["X-SubscriptionStatus"];
string deviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"];
TextBoxResponse.Text = notificationStatus + " | " + deviceConnectionStatus + " | " + notificationChannelStatus;
}
catch (Exception ex)
{
TextBoxResponse.Text = "Exception caught sending update: " + ex.ToString();
}
}
ご覧のとおり、「//トーストメッセージを作成する」というコードの一部があります。
タイルの更新でトーストを送信するにはどうすればよいですか?トーストメッセージが通過すると、タイルも更新され、ページに入力したのと同じ情報が表示されます。
現時点では、タイルのみが更新されます。
こちらもメインページの写真です。
長い投稿については大変申し訳ありませんが、できるだけ多くの情報を提供したいと思います。
使用-VisualStudio2012 / Windows Phone 8 / C#/ Silverlight
前もって感謝します。