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 ...
随机推荐
- Android 使用MediaStore.Images和 Cursor查询本地图片和图片缩略图
先看一个实例: String[] projection = { MediaStore.Images.Thumbnails._ID ,MediaStore.Images.Thumbnails.DATA} ...
- Eclipse开发Java EE应用
设置Web服务器 添加Web服务器 以上两步可以直接由下面这步完成: or 创建Web工程 建立JSP文件供测试 发布Java Web工程 方法1:在下方Server中添加 方法2:右击左边项目导航树 ...
- 六月计划#2B(6.10-6.16)
4/7 STL set 数学 快速傅立叶(FFT) 高斯消元 动态规划 斜率优化
- MVC3系列~Html.BeginForm与Ajax.BeginForm
Html.BeginForm与Ajax.BeginForm都是MVC架构中的表单元素,它们从字面上可以看到区别,即Html.BeginForm是普通的表单提交,而Ajax.BeginForm是支持异步 ...
- Android获取IMSI和IMEI
IMSI是一个 唯一的数字, 标识了GSM和UMTS 网络里的唯一一个用户. 它 存储 在手机的SIM卡里,它会通过手机发送到网络上. IMEI也是一串唯一的数字, 标识了 GSM 和 UMTS网络里 ...
- Error:Could not open initscript class cache for initialization script 'C:\Users\Avishek\AppData\Local\Temp\asLocalRepo14.gradle' (C:\Users\Avishek.gradle\caches\2.2.1\scripts\asLocalRepo14_dkwbdtenxxg
Error:Could not open initscript class cache for initialization script 见鬼 Android Studio打开项目时遇到这个问题 昨 ...
- Axis2 WebService(基于REST风格)
http://www.lifeba.org/arch/java_axis2_webservice_rest.html Axis2除了提供传统的webservice方法外,还提供了对Rest的支持.Ax ...
- Zookeeper的一致性协议:Zab(转)
Zookeeper使用了一种称为Zab(Zookeeper Atomic Broadcast)的协议作为其一致性复制的核心,据其作者说这是一种新发算法,其特点是充分考虑了Yahoo的具体情况:高吞吐量 ...
- 使用C#调用Python脚本,带参数列表 z
static void Main(string[] args) { string[] strArr;//参数列表 string sArguments = @"Pythons.py" ...
- [CODEVS1258]关路灯
题目描述 Description 多瑞卡得到了一份有趣而高薪的工作.每天早晨他必须关掉他所在村庄的街灯.所有的街灯都被设置在一条直路的同一侧. 多瑞卡每晚到早晨5点钟都在晚会上,然后他开始关灯.开始时 ...