开发者

Sending Push notification to a Windows Phone 7 device?

开发者 https://www.devze.com 2023-03-07 11:10 出处:网络
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 th

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

精彩评论

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

关注公众号