使用
1)到官方主页申请免费API, 下载 apns_beta_20110831.jar
2) 将apns_beta_20110831.jar添加到工程.
在工程上右键打开“属性”,选择 “Java Build Path”, 在 Libraries 中选择 “Add External JARs”, 选择下载的 apns_beta_20110831.jar.
3) 接收 push notification.
设备在接收到通知的时候会发送一个广播,通过使用BroadcastReceiver 接收并处理收到的通知.
4) 启动服务
发送Intent 启动服务,将 chanel 名字以及 此设备的标识 (chanel中唯一表示此设备的字符串) 传递过去:
Intent intent = new Intent(APNService.START);
intent.putExtra("ch", chanel);
intent.putExtra("devId", devId);
startService(intent);
notes: devId,标示此channel 中设备的唯一id, 可以是唯一用户名, uid, IMEI 等等.
5) 配置AndroidManifest.xml配置 Service/BroadcastReceiver,添加权限。
...
...
推送API:
通过Rect 接口发送通知到设备(登录 www.push-notification.mobi 会有一个测试平台):
http://www.push-notification.mobi/handlers/apns_v1.php ch=YourChannelId&devId=YourDevId&msg=”hello world”&random=0123&hash=HashCode
参数:
ch: api 的 channel Id.
devId: 接收设备的Id.
msg:要发送的消息.
random:一个随机数hash.
ch + g + msg + random + privateKey的MD5 校验码.
返回值:
服务器返回一 xml 格式字符串: