java实现window phone推送通知
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推送通知的更多相关文章
- 网络推送通知:及时,相关和准确 (navigator.serviceWorker.register(), window.PushManager, new Notification)
google网络推送通知 https://developers.google.cn/web/fundamentals/push-notifications/ 服务工作线程:简介server worle ...
- JavaScript是如何工作的: Web推送通知的机制
摘要: 如何在Web端推送消息? 这是专门探索 JavaScript 及其所构建的组件的系列文章的第9篇. 如果你错过了前面的章节,可以在这里找到它们: JavaScript是如何工作的:引擎,运行时 ...
- iOS 本地推送通知
1.什么是本地推送通知 不需要联网的情况下,应用程序经由系统发出的通知 2.本地推送的使用场景 定时提醒,如玩游戏.记账.闹钟.备忘录等 3.实现本地推送通知的步骤 创建本地推送通知的对象UILoca ...
- WP7推送通知服务
原文地址http://www.cnblogs.com/Joetao/articles/2214482.html (一)为什么使用推送通知服务(1)Windows Phone执行模型决定只有一个第三方的 ...
- Windows Azure Service Bus Notification Hub推送通知
前言 随着Windows Azure 在中国的正式落地,相信越来越多的人会体验到Windows Azure带来的强大和便利.在上一篇文章中, 我们介绍了如何利用Windows Azure中的Servi ...
- iOS 远程推送通知
1.什么是推送通知 在某些特殊情况下,应用程序被动收到的以不同种界面形式出现的提醒信息 推送通知的作用:可以让不在前台运行的app通知app发生了改变 iOS中得推送通知种类 远程推送通知(Remot ...
- Windows 8.1——将网站固定到开始菜单,自定义图标、颜色和Windows推送通知
记得在IE 9和Windows 7刚出来那会儿我写过一篇文章来介绍如何自定义网站将其固定到Windows的任务栏上,同时自定义图标及任务内容.那个功能在IE 9中被称之为JumpList.http:/ ...
- iOS推送通知的实现步骤
一.关于推送通知 来源:http://blog.csdn.net/enuola/article/details/8627283 推送通知,也被叫做远程通知,是在iOS 3.0以后被引入的功能.是当程序 ...
- Swift 本地推送通知UILocalNotification
Notification是智能手机应用开发中常用的信息传递机制,它不用消耗更多资源去不停的检查信息状态,可以非常好的节省资源. 在iOS中分为两种通知:本地.远程.本地的UILocalNotifica ...
随机推荐
- [Gauss]POJ3185 The Water Bowls
题意:反正就是要给的一串01的变成全0 能影响自己和左右 最少需要几步 01方程组 异或解 ][]; // 增广矩阵 ]; // 解 ]; // 标记是否为自由未知量 int n; void debu ...
- 【HDOJ】1197 Specialized Four-Digit Numbers
水题,暴力可解. #include <iostream> using namespace std; int chg(int n, int base); int main() { int i ...
- MySQL purge log简单吗
MySQL purge log简单吗? 简单: purge log的功能很简单,purge master logs to 指定一个binlog,然后删除之前的文件系统上的binlog文件,并更新bin ...
- C#中的cookie编程
Cookie就是所谓的" 小甜饼" ,他最早出现是在Netscape Navigator 2.0中.Cookie其实就是由Web服务器创建的.将信息存储在计算机上的文件.那么为什么 ...
- Azure Site Recovery:我们对于保障您的数据安全的承诺
Anoob Backer 云 + Enterprise 项目经理 Azure Site Recovery是一个基于 Azure的全天候.易用的服务,可以安全地安排恢复操作,一旦发生灾难,即可为您 ...
- Android学习之路——简易版微信为例(一)
这是“Android学习之路”系列文章的开篇,可能会让大家有些失望——这篇文章中我们不介绍简易版微信的实现(不过不是标题党哦,我会在后续博文中一步步实现这个应用程序的).这里主要是和广大园友们聊聊一个 ...
- SharePoint 2013版本功能对比介绍
转:http://www.fengfly.com/plus/view-213720-1.html 在SharePoint使用中,经常纠结于版本问题,SharePoint 2013主要有免费的Found ...
- CORREL
CORREL Show All Returns the correlation coefficient of the array1 and array2 cell ranges. Use the co ...
- HDU 5648 DZY Loves Math 暴力打表
题意:BC 76 div1 1003有中文题面 然后官方题解看不懂,我就不说了,然后看别人的题解 因为询问i,j最大都是15000,所以可以预处理,res[i][j]代表答案,然后显然这是开不下的,也 ...
- lightoj 1011 (状态压缩dp)
思路:状态压缩dp,设dp[i][j] 表示前i行,状态为j时的最大值,状态定义为:若前i行中取了第x列那么j的二进制位中第x位为1,否则为0,最后答案就是dp[n-1][(1 << n) ...