package com.windowphone.text;

import java.io.IOException;
import java.io.OutputStream;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.UUID;

public class HttpPost {

private String xml;
 private String url;

public HttpPost(String url, String xml) {
  this.xml = xml;
  this.url = url;
 }

private void Send() {
  
  HttpURLConnection con = null;
  URL url = null;
  try {
   url = new URL(this.url);
   con = (HttpURLConnection) url.openConnection();
   con.setRequestMethod("POST");
   con.setDoOutput(true);
   con.setDoInput(true);
   con.setUseCaches(false);
   
   //全球唯一的ID,类型:eb84a429-1ac6-46e2-b3f3-51929fd17648
   String guid = UUID.randomUUID().toString();  
   con.setRequestProperty("X-MessageID",guid);
   con.setRequestProperty("Content-Type","text/xml;charset=utf-8");
   
   //①Raw Notification模式
   //3:立刻发送 13:等待450秒发送 23:等待900秒发送
   con.setRequestProperty("X-NotificationClass", "3");
   
   
   //②Toast Notification模式
   //2:立刻发送 12:等待450秒发送 22:等待900秒发送
//   con.setRequestProperty("X-WindowsPhone-Target", "toast");
//   con.setRequestProperty("X-NotificationClass", "2");
   
   //③Tile Notification模式
   //1:立刻发送 11:等待450秒发送 21:等待900秒发送
//            con.setRequestProperty("X-WindowsPhone-Target", "token");
//            con.setRequestProperty("X-NotificationClass", "1");
            
   OutputStream out = con.getOutputStream();
   //在此要特别的小心,发送比特流,要把获取字节码改为utf-8,不然中文会乱码
   out.write(this.xml.getBytes("utf-8"));
   out.flush();
   
   //输出微软服务器response的情况,正常输出OK
   System.out.println("response:   "+con.getResponseMessage());
   
   out.close();
   con.disconnect();
  } catch (ConnectException ce) {
  } catch (IOException ie) {
  } catch (Exception e) {
  }
 }

public static void main(String[] args) {
  
  //这里直接复制window phone 应用注册微软的Uri
  String uri = "http://db3.notify.live.net/throttledthirdparty/01.00/AAGKzo1xh_AfR4Ia6ePTklzoAgAAAAADAQAAAAQUZm52OjIzOEQ2NDJDRkI5MEVFMEQ";
  
  ///①Raw Notification模式
  String rawMessage = "hitler 林楚金!";
  
  //②Toast Notification模式,固定模式,Text1和Text2两个参数
  String toastMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
        "<wp:Notification xmlns:wp=\"wpNotification\">" +
        "<wp:Toast>" +
        "<wp:Text1>123</wp:Text1>" +
        "<wp:Text2>林楚金</wp:Text2>" +
        "</wp:Toast>" +
        "</wp:Notification>";
  
  //③Tile Notification模式,固定模式,BackgroundImage背景图片,count数量,Title小标题
  String tileMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
        "<wp:Notification xmlns:wp=\"wpNotification\">" +
        "<wp:Tile>" +
        "<wp:BackgroundImage>/Images/天晴.jpg</wp:BackgroundImage>" +
        "<wp:Count>2</wp:Count>" +
        "<wp:Title>fuck 林楚金</wp:Title>" +
        "</wp:Tile>" +
        "</wp:Notification>";
    
  HttpPost post = new HttpPost(uri,rawMessage);
  
  post.Send();
 }

}

java实现window phone推送通知的更多相关文章

  1. 网络推送通知:及时,相关和准确 (navigator.serviceWorker.register(), window.PushManager, new Notification)

    google网络推送通知 https://developers.google.cn/web/fundamentals/push-notifications/ 服务工作线程:简介server worle ...

  2. JavaScript是如何工作的: Web推送通知的机制

    摘要: 如何在Web端推送消息? 这是专门探索 JavaScript 及其所构建的组件的系列文章的第9篇. 如果你错过了前面的章节,可以在这里找到它们: JavaScript是如何工作的:引擎,运行时 ...

  3. iOS 本地推送通知

    1.什么是本地推送通知 不需要联网的情况下,应用程序经由系统发出的通知 2.本地推送的使用场景 定时提醒,如玩游戏.记账.闹钟.备忘录等 3.实现本地推送通知的步骤 创建本地推送通知的对象UILoca ...

  4. WP7推送通知服务

    原文地址http://www.cnblogs.com/Joetao/articles/2214482.html (一)为什么使用推送通知服务(1)Windows Phone执行模型决定只有一个第三方的 ...

  5. Windows Azure Service Bus Notification Hub推送通知

    前言 随着Windows Azure 在中国的正式落地,相信越来越多的人会体验到Windows Azure带来的强大和便利.在上一篇文章中, 我们介绍了如何利用Windows Azure中的Servi ...

  6. iOS 远程推送通知

    1.什么是推送通知 在某些特殊情况下,应用程序被动收到的以不同种界面形式出现的提醒信息 推送通知的作用:可以让不在前台运行的app通知app发生了改变 iOS中得推送通知种类 远程推送通知(Remot ...

  7. Windows 8.1——将网站固定到开始菜单,自定义图标、颜色和Windows推送通知

    记得在IE 9和Windows 7刚出来那会儿我写过一篇文章来介绍如何自定义网站将其固定到Windows的任务栏上,同时自定义图标及任务内容.那个功能在IE 9中被称之为JumpList.http:/ ...

  8. iOS推送通知的实现步骤

    一.关于推送通知 来源:http://blog.csdn.net/enuola/article/details/8627283 推送通知,也被叫做远程通知,是在iOS 3.0以后被引入的功能.是当程序 ...

  9. Swift 本地推送通知UILocalNotification

    Notification是智能手机应用开发中常用的信息传递机制,它不用消耗更多资源去不停的检查信息状态,可以非常好的节省资源. 在iOS中分为两种通知:本地.远程.本地的UILocalNotifica ...

随机推荐

  1. 【Linux远程管理】RDP协议远程管理

    RDP(Remote Desk Protocol).远程桌面协议,常用的Windows操作系统的远程桌面管理就就是基于该协议. 而在Linux下,我们也是可以找到开源的rdp server的,这就是x ...

  2. 奇怪的JS

    有的时候发现JS是一门很高深的语言,不是我等俗人可以学会,没有private,没有public不说,居然连Class都没有,这个世界就是这样,有的东西你不一定非要想通,也不一定非要剖根问底,有的时候你 ...

  3. JQuery实现点击div以外的位置隐藏该div窗口

    简单示例代码: <body> <script type="text/javascript" src="http://ajax.googleapis.co ...

  4. hdu4722Good Numbers(dp)

    链接 这题规律其实挺明显的 打表找规律估计都可以 正规点就是DP 算出第N位所包含的good number的数量 如果给出的数是N+1位 就枚举各位上比原来小的数 加上下一位的dp值 一个i写成g了 ...

  5. E212: 不能以写入模式打开 linux

    跟大家讲解下事情发生的情况 背景:linux下有多个用户     每个用户有自己的密码   还有root用户 事由:我用zhengdengping用户登录    想去拷贝点 用户 lixianchu ...

  6. bzoj2763: [JLOI2011]飞行路线 分层图+dij+heap

    分析:d[i][j]代表从起点到点j,用了i次免费机会,那就可以最短路求解 #include <stdio.h> #include <iostream> #include &l ...

  7. C#学习:集合、迭代、泛型(1)

    一.System.Collections名称空间下几个接口表征着集合的功能: 1.IEnumerable:表征着迭代功能 public interface IEnumerable { IEnumera ...

  8. SPI协议及其工作原理浅析

    转载自:http://bbs.chinaunix.net/thread-1916003-1-1.html一.概述. SPI, Serial Perripheral Interface, 串行外围设备接 ...

  9. 【原创】Mac上编译Hadoop1.0.3出现的一些问题

    create-native-configure: [exec] configure.ac:47: error: possibly undefined macro: AC_PROG_LIBTOOL [e ...

  10. HW2.18

    public class Solution { public static void main(String[] args) { System.out.println("a" + ...