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. Asp.Net中的三种分页方式

    Asp.Net中的三种分页方式 通常分页有3种方法,分别是asp.net自带的数据显示空间如GridView等自带的分页,第三方分页控件如aspnetpager,存储过程分页等. 第一种:使用Grid ...

  2. ubuntu使用中的一些问题

    ubuntu如何修改计算机名? sudo gedit /etc/hostname 如何查看ubuntu操作系统位数 方法1: #查看long的位数,返回32或64 getconf LONG_BIT 方 ...

  3. solr的原子更新/局部更新

    solr支持三种类型的原子更新: set - to set a field. add - to add to a multi-valued field. inc - to increment a fi ...

  4. CPU Benchmarks

    http://www.cpubenchmark.net/high_end_cpus.html 非常清楚~~~

  5. linux下查看防火墙当前状态,开启关闭等

    从配置菜单关闭防火墙是不起作用的,索性在安装的时候就不要装防火墙 查看防火墙状态: /etc/init.d/iptables status 暂时关闭防火墙: /etc/init.d/iptables  ...

  6. C# zip压缩

    /**//* * Gary Zhang -- cbcye@live.com * www.cbcye.com * www.quicklearn.cn * cbcye.cnblogs.com */ usi ...

  7. WCF - Hosting WCF Service

    After creating a WCF service, the next step is to host it so that the client applications can consum ...

  8. Android开发UI之个性化控件之Menu

    MenuDrawer 滑出式菜单,通过拖动屏幕边缘滑出菜单,支持屏幕上下左右划出,支持当前View处于上下层,支持Windows边缘.ListView边缘.ViewPager变化划出菜单等. 项目地址 ...

  9. 用 C# 读取二进制文件

    当想到所有文件都转换为 XML时,确实是一件好事.但是,这并非事实.仍旧还有大量的文件格式不是XML,甚至也不是ASCII.二进制文件仍然在网络中传播,储存在磁盘上,在应用程序之间传递.相比之下,在处 ...

  10. powerdesigner导出SQL时大写转换

    打开物理模型,点击菜单“Tools->Execute Commands -> Edit/Run Script...",或者快捷键(Ctrl+Shift+X)执行下面vbscrip ...