友盟推送 java例子_Java 友盟推送

本文展示了如何使用Java实现友盟推送,包括Android自定义广播通知、iOS单播消息以及Android和iOS的文件播。通过设置不同参数,如消息内容、设备标识、自定义字段等,实现对不同平台的消息推送。
摘要由CSDN通过智能技术生成

import org.json.JSONObject;

import com.ytdinfo.core.umeng.FileInfo;

import com.ytdinfo.core.umeng.Message;

import push.android.AndroidCustomizedcast;

import push.android.AndroidFilecast;

import push.ios.IOSCustomizedcast;

import push.ios.IOSFilecast;

import push.ios.IOSUnicast;public classPushMessageUtil {//安卓notification

public staticboolean sendAndroidCustomizedcastNotification(Message message) throws Exception {

AndroidCustomizedcast customizedcast= newAndroidCustomizedcast();

customizedcast.setAppMasterSecret(message.getAndroidMasterSecret());

customizedcast.setPredefinedKeyValue("appkey", message.getAndroidAppKey());

customizedcast.setPredefinedKeyValue("timestamp", Integer.toString((int) (System.currentTimeMillis() / 1000L)));

customizedcast.setPredefinedKeyValue("type", message.getType());

customizedcast.setPredefinedKeyValue("device_tokens", message.getDeviceTokens());

customizedcast.setPredefinedKeyValue("display_type", "notification");//customizedcast.setPredefinedKeyValue("display_type", "message");

customizedcast.setPredefinedKeyValue("ticker", message.getContent());

customizedcast.setPredefinedKeyValue("title", message.getTitle());

customizedcast.setPredefinedKeyValue("text", message.getContent());

customizedcast.setPredefinedKeyValue("after_open", "go_custom");

customizedcast.setPredefinedKeyValue("custom", message.getCustom());

customizedcast.setPredefinedKeyValue("production_mode", "false");

customizedcast.setPredefinedKeyValue("description", message.getContent());//set custom field

JSONObject customJson = newJSONObject();

customJson.put("msgtype", (String) message.getMsgtype());

customJson.put("objectid", message.getObjectid());

customJson.put("content", (String) message.getContent());

customJson.put("studentId", (String) message.getStudentId());

customJson.put("studentName", (String) message.getStudentName());

customizedcast.setPredefinedKeyValue("custom", customJson);returncustomizedcast.send();

}//ios推送消息

public staticboolean sendIOSCustomizedcast(Message message) throws Exception {

IOSUnicast unicast= newIOSUnicast();

unicast.setAppMasterSecret((String) message.getIosMasterSecret());

unicast.setPredefinedKeyValue("appkey", message.getIosAppKey());

unicast.setPredefinedKeyValue("timestamp", Integer.toString((int) (System.currentTimeMillis() / 1000L)));

unicast.setPredefinedKeyValue("device_tokens", message.getDeviceTokens());//customizedcast.setPredefinedKeyValue("display_type", "notification");//customizedcast.setPredefinedKeyValue("display_type", "message");

unicast.setPredefinedKeyValue("alert", message.getContent());

unicast.setPredefinedKeyValue("badge", Integer.valueOf(1));

unicast.setPredefinedKeyValue("sound", "default");

unicast.setPredefinedKeyValue("content-available", message.getContent());

unicast.setPredefinedKeyValue("description", message.getContent());

unicast.setPredefinedKeyValue("production_mode", "false");//custom field

unicast.setCustomizedField("msgtype", (String) message.getMsgtype());

unicast.setCustomizedField("objectid", message.getObjectid());

unicast.setCustomizedField("content", (String) message.getContent());

unicast.setCustomizedField("studentId", (String) message.getStudentId());

unicast.setCustomizedField("studentName", (String) message.getStudentName());returnunicast.send();

}//安卓发送文件播

public static voidsendAndroidFilecast(FileInfo fileInfo) throws Exception {

AndroidFilecast filecast= newAndroidFilecast();

filecast.setAppMasterSecret(fileInfo.getAndroidMasterSecret());

filecast.setPredefinedKeyValue("appkey", fileInfo.getAppkey());

filecast.setPredefinedKeyValue("timestamp", Integer.toString((int) (System.currentTimeMillis() / 1000L)));

filecast.uploadContents(fileInfo.getContent());

filecast.setPredefinedKeyValue("ticker", "Android filecast ticker");

filecast.setPredefinedKeyValue("title", fileInfo.getTitle());

filecast.setPredefinedKeyValue("text", fileInfo.getText());

filecast.setPredefinedKeyValue("after_open", "go_app");

filecast.setPredefinedKeyValue("display_type", "notification");

filecast.send();

}//Ios发送文件播

public voidsendIOSFilecast(FileInfo fileInfo) throws Exception {

IOSFilecast filecast= newIOSFilecast();

filecast.setAppMasterSecret(fileInfo.getIosMasterSecret());

filecast.setPredefinedKeyValue("appkey", fileInfo.getAppkey());

filecast.setPredefinedKeyValue("timestamp", Integer.toString((int) (System.currentTimeMillis() / 1000L)));

filecast.uploadContents(fileInfo.getContent());

filecast.setPredefinedKeyValue("alert", "IOS 文件播测试");

filecast.setPredefinedKeyValue("badge", Integer.valueOf(0));

filecast.setPredefinedKeyValue("sound", "chime");

filecast.setPredefinedKeyValue("production_mode", "true");

filecast.send();

}public static voidmain(String[] args) {}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值