消息推送
ACNotificationMgr
集成了友盟推送,并提供了访问AbleCloud消息推送相关的接口。
指定设备发送通知
// 实例化ACNotificationMgr
ACNotificationMgr notificationMgr = ac.notificationMgr(ac.newContext());
ACNotification notification = new ACNotification("testing", "I'm testing notification");
// 向绑定该设备的所有用户推送消息
// 参数deviceId为设备逻辑ID
ac.notificationMgr(ac.newContext()).sendNotification(deviceId, ACNotificationMgr.NOTIFY_ALL_USER, notification);
指定用户发送通知
// 实例化ACNotificationMgr
ACNotificationMgr notificationMgr = ac.notificationMgr(ac.newContext());
ACNotification notification = new ACNotification("testing", "I'm testing notification");
// 指定用户ID为1和2
List<Long> userList = new ArrayList<Long>();
userList.add(1L);
userList.add(2L);
// 指定用户推送消息
ac.notificationMgr(ac.newContext()).sendNotification(userList, notification);
附录
public class ACNotification {
public static final long GO_APP = 0;
public static final long GO_URL = 1;
public static final long GO_ACTIVITY = 2;
public static final long NOTIFICATION = 0;
public static final long MESSAGE = 1;
// 通知显示类型
// NOTIFICATION 通知,MESSAGE 消息
private long displayType;
// 通知标题
private String title;
// 通知内容
private String content;
// 是否振动
private boolean vibrate;
// 是否呼吸灯
private boolean lights;
// 是否响铃
private boolean sound;
// 点击通知时的动作类型
// GO_APP:跳转到APP, GO_URL:跳转到指定url, GO_ACTIVITY:跳转到指定activity
private long openType;
// 当openType为GO_URL时指定url地址
private String url;
// 当openType为GO_ACTIVITY时指定activity
private String activity;
// 用户自定义数据
private Map<String, String> userData;
// 本地化自定义格式
private String locKey;
// 本地化自定义参数
private List<String> locArgs;
public ACNotification() {
this.title = "";
this.content = "";
this.vibrate = true;
this.lights = true;
this.sound = true;
this.openType = GO_APP;
this.url = "";
this.activity = "";
this.userData = new HashMap();
this.locKey = "";
this.locArgs = new ArrayList();
}
public ACNotification(String title, String content) {
this.displayType = NOTIFICATION;
this.title = title;
this.content = content;
this.vibrate = true;
this.lights = true;
this.sound = true;
this.openType = GO_APP;
this.url = "";
this.activity = "";
this.userData = new HashMap();
this.locKey = "";
this.locArgs = new ArrayList();
}
//getter
}