极光推送,标签、别名、广播方式。
public static void main(String[] args) throws APIConnectionException, APIRequestException { pushNotice("","baojing","网页内容","网页标题"); } private static final String MASTER_SECRET = "---------"; private static final String APP_KEY = "---------"; // private static JPushClient jPushClient=new JPushClient(MASTER_SECRET,APP_KEY); public static void pushNotice(String type, String alias, String context, String title){ PushPayload.Builder builder= PushPayload.newBuilder(); builder.setPlatform(Platform.all());//设置接受的平台,all为所有平台,包括安卓、ios、和微软的 //设置如果用户不在线、离线消息保存的时间 Options options=Options.sendno(); options.setTimeToLive(86400l); //设置为86400为保存一天,如果不设置默认也是保存一天 builder.setOptions(options); //设置推送方式 // if(type.equals("alias")){ // builder.setAudience(Audience.alias(alias));//根据别名推送 // }else if(type.equals("tag")){ builder.setAudience(Audience.tag(alias));//根据标签推送 // }else{ // builder.setAudience(Audience.all());//Audience设置为all,说明采用广播方式推送,所有用户都可以接收到 // } //设置为采用通知的方式发送消息 // builder.setNotification(Notification.alert(title)); Notification android = Notification.android(context, title,null); builder.setNotification(android); //builder.setNotification(Notification.alert(alert)); PushPayload pushPayload=builder.build(); try{ //进行推送,实际推送就在这一步 PushResult pushResult=jPushClient.sendPush(pushPayload); System.out.println(pushResult); }catch(Exception e){ e.printStackTrace(); } }