引入jpush sdk

    cn.jpush.api    jpush-client    3.3.13
public class JpushClientUtils {    private final static String masterSecret = "xxxxx";    private final static String appKey = "xxxxx";    private final static Integer SUCCESS = 200;    private static JPushClient jPushClient = new JPushClient(masterSecret,appKey);    //定时发送[-android    public static String sendScheduleAndroid(Map parm){        PushPayload payload = PushPayload.newBuilder()                .setPlatform(Platform.android())                .setAudience(Audience.all())                .setNotification(Notification.newBuilder()                        .addPlatformNotification(AndroidNotification.newBuilder()                                .addExtras(parm)                                .setTitle(parm.get("title"))  //标题                                .setAlert(parm.get("content")) //内容                                .setAlertType(1) //默认提示音                                .build())                        .build())                .setOptions(Options.newBuilder().setApnsProduction(true).build())//false-开发环境,true-生产环境,android不区分环境                .build();        try {            try {                ScheduleResult singleSchedule = jPushClient.createSingleSchedule("schedule",parm.get("date"), payload);//时间                System.out.println(singleSchedule.isResultOK());                if( singleSchedule.getResponseCode() == SUCCESS){                    return singleSchedule.getSchedule_id();                }            } catch (APIConnectionException e) {                e.printStackTrace();            }        } catch (APIRequestException e) {            e.printStackTrace();        }        return null;    }    public static String sendScheduleIOS(Map parm){        PushPayload payload = PushPayload.newBuilder()                .setPlatform(Platform.ios())                .setAudience(Audience.all())                .setNotification(Notification.newBuilder()                        .addPlatformNotification(IosNotification.newBuilder()                                .setAlert(IosAlert.newBuilder()                                        .setTitleAndBody(parm.get("title"),"",parm.get("content")).build())                                .setBadge(+1)                                .setSound("happy")                                .addExtras(parm)                                .build())                        .build())                .setOptions(Options.newBuilder().setApnsProduction(true).build())                .build();        try {            try {                ScheduleResult singleSchedule = jPushClient.createSingleSchedule("schedule",parm.get("date"), payload);                System.out.println(singleSchedule.isResultOK());                System.out.println(singleSchedule.getSchedule_id());                if( singleSchedule.getResponseCode() == SUCCESS){                    return singleSchedule.getSchedule_id();                }            } catch (APIConnectionException e) {                e.printStackTrace();            }        } catch (APIRequestException e) {            e.printStackTrace();        }        return null;    }    public static String sendScheduleAll(Map parm){        PushPayload payload = PushPayload.newBuilder()                .setPlatform(Platform.all())                .setAudience(Audience.all())                .setNotification(Notification.newBuilder()                        .addPlatformNotification(IosNotification.newBuilder()                                .setAlert(parm.get("content"))                                .setBadge(+1)                                .setSound("happy")                                .addExtras(parm)                                .build())                        .addPlatformNotification(AndroidNotification.newBuilder()                                .addExtras(parm)                                .setTitle(parm.get("title"))                                .setAlert(IosAlert.newBuilder()                                        .setTitleAndBody(parm.get("title"),"",parm.get("content")).build())                                .setAlertType(1)                                .build())                        .build())                .setOptions(Options.newBuilder().setApnsProduction(true).build())                .build();        try {            try {                ScheduleResult singleSchedule = jPushClient.createSingleSchedule("schedule",parm.get("date"), payload);                System.out.println(singleSchedule.isResultOK());                System.out.println(singleSchedule.getSchedule_id());                if( singleSchedule.getResponseCode() == SUCCESS){                    return singleSchedule.getSchedule_id();                }            } catch (APIConnectionException e) {                e.printStackTrace();            }        } catch (APIRequestException e) {            e.printStackTrace();        }        return null;    }    //极光推送>>Android    public static Long jpushAndroid(Map parm) {        PushPayload payload = PushPayload.newBuilder()                .setPlatform(Platform.android())                .setAudience(Audience.all())                .setNotification(Notification.newBuilder()                        .addPlatformNotification(AndroidNotification.newBuilder()                                .addExtras(parm)                                .setTitle(parm.get("title"))                                .setAlert(parm.get("content"))                                .setAlertType(1)                                .build())                        .build())                .setMessage(Message.content(parm.get("content")))                .setOptions(Options.newBuilder().setApnsProduction(true).build())                .build();        try {            PushResult pu = jPushClient.sendPush(payload);            if( pu.getResponseCode() == SUCCESS){                return pu.msg_id;            }        } catch (APIConnectionException e) {            e.printStackTrace();        } catch (APIRequestException e) {            e.printStackTrace();        }        return null;    }    //极光推送>>ios    public static  Long jpushIOS(Map parm) {        PushPayload payload = PushPayload.newBuilder()                .setPlatform(Platform.ios())                .setAudience(Audience.all())                .setNotification(Notification.newBuilder()                        .addPlatformNotification(IosNotification.newBuilder()                                .setAlert(IosAlert.newBuilder()                                        .setTitleAndBody(parm.get("title"),"",parm.get("content")).build())                                .setBadge(+1)                                .setSound("happy")                                .addExtras(parm)                                .build())                        .build())                .setOptions(Options.newBuilder().setApnsProduction(true).build())                .build();        try {            PushResult pu = jPushClient.sendPush(payload);            if( pu.getResponseCode() == SUCCESS){                return pu.msg_id;            }        } catch (APIConnectionException e) {            e.printStackTrace();        } catch (APIRequestException e) {            e.printStackTrace();        }        return null;    }    //极光推送>>All所有平台    public static Long jpushAll(Map parm) {        PushPayload payload = PushPayload.newBuilder()                .setPlatform(Platform.all())                .setAudience(Audience.all())                .setNotification(Notification.newBuilder()                        .addPlatformNotification(IosNotification.newBuilder()                                .setAlert(IosAlert.newBuilder()                                        .setTitleAndBody(parm.get("title"),"",parm.get("content")).build())                                .setBadge(+1)                                .setSound("happy")                                .addExtras(parm)                                .build())                        .addPlatformNotification(AndroidNotification.newBuilder()                                .addExtras(parm)                                .setTitle(parm.get("title"))                                .setAlert(parm.get("content"))                                .setAlertType(1)                                .build())                        .build())                .setOptions(Options.newBuilder().setApnsProduction(true).build())                .build();        try {            PushResult pu = jPushClient.sendPush(payload);            if( pu.getResponseCode() == SUCCESS){                return pu.msg_id;            }        } catch (APIConnectionException e) {            e.printStackTrace();        } catch (APIRequestException e) {            e.printStackTrace();        }        return null;    }    public static  Long jpushIOStest(Map parm) {        JsonObject object = new JsonObject();        object.addProperty("title","ceshi title");        object.addProperty("body","ceshi body");        JSONObject jsonObject = new JSONObject();        IosAlert.Builder builder = new IosAlert.Builder();        builder.setTitleAndBody("title111","subtitle","body111");        //创建JPushClient        PushPayload payload = PushPayload.newBuilder()                .setPlatform(Platform.ios())                .setAudience(Audience.all())                .setNotification(Notification.newBuilder()                        .addPlatformNotification(IosNotification.newBuilder()                                .setAlert(object)//                                .setAlert(IosAlert.newBuilder()//                                        .setTitleAndBody("title","subtitle","neirong").build())                                .setBadge(+1)                                .setSound("happy")//                                .addExtras(parm)                                .build())                        .build())                .setOptions(Options.newBuilder().setApnsProduction(true).build())                .build();        try {            PushResult pu = jPushClient.sendPush(payload);            if( pu.getResponseCode() == SUCCESS){                return pu.msg_id;            }        } catch (APIConnectionException e) {            e.printStackTrace();        } catch (APIRequestException e) {            e.printStackTrace();        }        return null;    }   }

集成ios推送标题+内容需要注意的地方:

IosNotification.newBuilder() .setAlert(object)   Alert可以是string、object,需要注意一下JsonObject是gson而不是JSONObject;

别忘了build()初始化相应的对象

 

 

更多相关文章

  1. linux下编译MTK android的环境搭建
  2. cocos2d-x 3.0 bata for android环境配置
  3. android混淆文件
  4. Android(安卓)AndroidStudio环境下控制状态栏颜色
  5. 监听网络变化的广播
  6. Ubuntu16.04上Android(安卓)N开发环境配置
  7. Android:StartActivies(Intent[] intents)用法
  8. Android学习笔记一:Android开发环境搭建和第一个应用程序
  9. Cygwin环境下使用Android(安卓)NDK r9c编译boost 1.55

随机推荐

  1. android 倒影
  2. android 多张图片动画方式轮播(转载)
  3. Vitamio打造android个性化得播放器
  4. Android 自定义文本框(带图片)
  5. Android 获取当前语言的方法1
  6. android 自动化测试 monkey
  7. Android的setTag
  8. Android延时执行的几种方法
  9. Android实现倒计时启动功能的实现
  10. Android studio 启动模拟器报错-Turn off