开发者

Sending Push notification to a Windows Phone 7 device?

So if I have my own game and server, how can I send push notifications to that device from my server, you know like a message that the appl开发者_JAVA百科ication reads and display it to the user on the screen?

Sorry Im a noob when it comes to push notifications.


Where have you started looking?

Windows Phone 7 supports a few different notifications, such as Toast, Live Tiles, Raw, etc.

I'd recommend starting here and reading about them a bit more, and follow the links to the appropriate documentation and examples.


I am sending you the working code for toast push notification.

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();


Yes you can send, but why should you send a push notification ? use live tile notification for that. use hubtile from Windows phone toolkit and add the Hub to the Visual tree, and do hubtile1.Notification ="Something you want to send as push notification";

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜