向 Windows Phone 7 设备发送推送通知



那么,如果我有自己的游戏和服务器,我如何从我的服务器向该设备发送推送通知,你知道应用程序读取并在屏幕上向用户显示一条消息?

对不起,在推送通知方面,我是一个菜鸟。

你从哪里开始寻找的?

Windows Phone 7支持几种不同的通知,如Toast,Live Tiles,Raw等。

我建议从这里开始,阅读更多关于它们的信息,并点击相应文档和示例的链接。

我正在向您发送 toast 推送通知的工作代码。

String toastMessage = "<?xml version="1.0" encoding="utf-8"?>" +
 "<wp:Notification xmlns:wp="WPNotification">" +
     "<wp:Toast>" +
          "<wp:Text1> Welcome To Windows Push &lt;/wp:Text1>" +
     "</wp:Toast> " +
  "</wp:Notification>";

byte[] notificationMessage = toastMessage.getBytes();
url = new URL(subscriptionURI); //You must have the subscription URI provided by MPNS to client side.
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("ContentLength", String.valueOf(notificationMessage.length));
connection.setRequestProperty("ContentType", "text/xml");
connection.addRequestProperty("X-WindowsPhone-Target", "toast");
connection.addRequestProperty("X-NotificationClass", "2");
connection.connect();
DataOutputStream out = 
    new DataOutputStream(
        connection.getOutputStream());
out.write(notificationMessage, 0, notificationMessage.length);
out.close();

是的,您可以发送,但为什么要发送推送通知? 为此使用动态磁贴通知。使用 Windows Phone 工具包中的 Hubtile 并将 Hub 添加到可视化树中,然后执行 hubtile1.Notification ="Something you want to send as push notification";

最新更新