1.下载SDK
REST API为极光推送开发API
2.下载好后,maven导入后可以参考示例
官方demo
4.小demo
// 设置好账号的app_key和masterSecret是必须的 private static String APP_KEY = "你的app_key"; private static String MASTER_SECRET = "你的master_secret"; //极光推送>>Android //Map<String, String> parm是我自己传过来的参数,同学们可以自定义参数 public static void jpushAndroid(Map<String, String> parm) { Map<String, String> extras = new HashMap<String, String>(); // extras.put("test", "https://community.jiguang.cn/push"); extras.put("type", "2");//变色龙云必须设置type=2 extras.put("url", "http://localhost:8080/index"); //创建JPushClient JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY); //推送的关键,构造一个payload PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.android())//指定android平台的用户 .setAudience(Audience.tag("122222222233333")) //.setAudience(Audience.registrationId(parm.get("id")))//registrationId指定用户 .setNotification(Notification.android("hello123", "", extras)) // .setNotification(Notification.newBuilder() // .addPlatformNotification(AndroidNotification.newBuilder() // .addExtras(extras) // .setAlert("不通过") // .setTitle("审核不通过") // .build()) // .build()) //发送内容 // .setOptions(Options.newBuilder().setApnsProduction(false).build()) // //这里是指定开发环境,不用设置也没关系 // .setMessage(Message.content("hi123"))//自定义信息 .build(); try { PushResult pu = jpushClient.sendPush(payload); System.out.println(pu.toString()); } catch (APIConnectionException e) { e.printStackTrace(); } catch (APIRequestException e) { e.printStackTrace(); } }