1、首先申请key

https://www.jiguang.cn/accounts/login/form

2、app build.gradle添加jar依赖

compile 'cn.jiguang.sdk:jpush:3.0.7'
compile 'cn.jiguang.sdk:jcore:1.1.3'
compile 'me.leolin:ShortcutBadger:1.1.16@aar'//消息桌面显示

注意最新依赖是:

compile 'cn.jiguang.sdk:jpush:3.1.6'  // 此处以JPush 3.1.6 版本为例。
compile 'cn.jiguang.sdk:jcore:1.2.5'  // 此处以JCore 1.2.5 版本为例。

在defaultConfig下添加key配置

manifestPlaceholders = [JPUSH_PKGNAME : applicationId,JPUSH_APPKEY : "880fe88703ab92260d7d42ca", //JPush上注册的包名对应的appkey.JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
]

如果项目加入了百度导航,需要在defaultConfig下添加系统配置

ndk {abiFilters "armeabi", "x86", "x86_64", "mips64", "mips"
}

3、主要receiver

/*** ProjectName: Myditukaifa* Author: lgq* Date: 2018/1/30 0030 14:37*/public class MyJPushReceiver extends BroadcastReceiver {private String body;private int num;//    private Intent mForegroundService;private int tzid=0;@Overridepublic void onReceive(Context context, Intent intent) {try {Bundle bundle = intent.getExtras();String action = intent.getAction();Log.i("lgqq","body=====自定义消息="+action);if (action.equals("cn.jpush.android.intent.NOTIFICATION_OPENED")) {//处理点击事件ShareUtil.sharedPint("num",0);ShortcutBadger.removeCount(context); //for 1.1.4+ 桌面信息context.startActivity(new Intent(context, ShowJpushActivity.class).putExtra("tz",bundle.getString("cn.jpush.android.ALERT")));}if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {//注册
//                Util.soutLong(TAG, "JPush用户注册成功");} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {// 这里会显示极光推送默认的通知,自定义能力有限int num = ShareUtil.getSharedInt("num");num++;ShareUtil.sharedPint("num",num);ShortcutBadger.applyCount(context, num);Log.i("lgqq","body=====通知="+bundle.getString("cn.jpush.android.ALERT"));}String param = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);Log.v("lgqq","body=====action="+num+".........."+param);if (action.equals("cn.jpush.android.intent.NOTIFICATION_RECEIVED")) {//处理滑动清除和点击删除事件Log.v("lgqq","body=====shoudaotz=");}body = bundle.getString("cn.jpush.android.ALERT");Log.v("lgqq","body======"+body);if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);Logger.d("[MyReceiver] 接收Registration Id : " + regId);//send the Registration Id to your server...
//                EventBus.getDefault().post(new LoginEvent(regId));} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {Logger.d("[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE));Log.i("lgqq","body=====接受到推送下来的消息=666666666666自定义消息6");tzid=tzid+1;int num = ShareUtil.getSharedInt("num");num++;ShareUtil.sharedPint("num",num);ShortcutBadger.applyCount(context, num);processCustomMessage(context, bundle);} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {Logger.d("[MyReceiver] 接收到推送下来的通知");int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);Logger.d("[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId);}  else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {Logger.d("[MyReceiver] 用户收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA));//在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码,比如打开新的Activity, 打开一个网页等..} else if(JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);Logger.w("[MyReceiver]" + intent.getAction() +" connected state change to "+connected);} else {Logger.d("[MyReceiver] Unhandled intent - " + intent.getAction());}} catch (Exception e){}
//        context.startActivity(new Intent(context, TwoAcitvity.class));}//send msg to MainActivitypublic String getTime(){long currentTime = System.currentTimeMillis();SimpleDateFormat formatter = new SimpleDateFormat("HH时mm分");Date date = new Date(currentTime);System.out.println(formatter.format(date));//        long time=System.currentTimeMillis()/1000;//获取系统时间的10位的时间戳String  str=String.valueOf(formatter.format(date));return str;}private void processCustomMessage(Context context, Bundle bundle) {RemoteViews customView = new RemoteViews(context.getPackageName(), R.layout.kongreveiver);NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);String time = getTime();
//                        String hhmm = timetodate(time);customView.setTextViewText(R.id.timemy,time);if (!TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_TITLE))){customView.setTextViewText(R.id.name,bundle.getString(JPushInterface.EXTRA_TITLE));}customView.setTextViewText(R.id.neirongte,bundle.getString(JPushInterface.EXTRA_MESSAGE));Intent intentCancel = new Intent(context,NotificationBroadcastReceiver.class);PendingIntent pendingIntentCancel = PendingIntent.getBroadcast(context,0,intentCancel,PendingIntent.FLAG_ONE_SHOT);Intent companyIntroduce = new Intent(context, ShowJpushActivity.class);companyIntroduce.putExtra("tz",bundle.getString(JPushInterface.EXTRA_MESSAGE));
//        companyIntroduce.putExtra("name", name);int notifyId = (int) System.currentTimeMillis();PendingIntent pendingIntent = PendingIntent.getActivity(context, notifyId, companyIntroduce, PendingIntent.FLAG_UPDATE_CURRENT);NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);mBuilder//设置通知栏标题
//                                .setContentText(bundle.getString(JPushInterface.EXTRA_MESSAGE)) //设置通知栏显示内容.setContent(customView).setContentIntent(pendingIntent) //设置通知栏点击意图.setDeleteIntent(pendingIntentCancel)//取消消息回调
//                .setTicker(context.getPackageName() + "消息")//通知首次出现在通知栏,带上升动画效果的.setWhen(System.currentTimeMillis())//通知产生的时间,会在通知信息里显示,一般是系统获取到的时间.setPriority(Notification.PRIORITY_DEFAULT) //设置该通知优先级.setAutoCancel(true)//设置这个标志当用户单击面板就可以让通知将自动取消
//.setOngoing(false)//ture,设置他为一个正在进行的通知。他们通常是用来表示一个后台任务,用户积极参与(如播放音乐)或以某种方式正在等待,因此占用设备(如一个文件下载,同步操作,主动网络连接)//                                .setDefaults(Notification.DEFAULT_VIBRATE)//向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合
//                                .setDefaults(Notification.DEFAULT_SOUND)
//Notification.DEFAULT_ALL  Notification.DEFAULT_SOUND 添加声音 // requires VIBRATE permission.setSmallIcon(R.mipmap.mylog);
//        mNotificationManager.notify(notifyId, notify);Log.i("lgqq","body=====id============"+tzid+".....");int num = ShareUtil.getSharedInt("num");num++;ShareUtil.sharedPint("num",num);mNotificationManager.notify(num, mBuilder.build());}}

4、次要receiver

/*** 自定义JPush message 接收器,包括操作tag/alias的结果返回(仅仅包含tag/alias新接口部分)* */
public class MyJPushMessageReceiver extends JPushMessageReceiver {@Overridepublic void onTagOperatorResult(Context context, JPushMessage jPushMessage) {
//        TagAliasOperatorHelper.getInstance().onTagOperatorResult(context,jPushMessage);Log.i("lgqq","body=====1111111=");super.onTagOperatorResult(context, jPushMessage);}@Overridepublic void onCheckTagOperatorResult(Context context,JPushMessage jPushMessage){
//        TagAliasOperatorHelper.getInstance().onCheckTagOperatorResult(context,jPushMessage);Log.i("lgqq","body=====2222222=");super.onCheckTagOperatorResult(context, jPushMessage);}@Overridepublic void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {Log.i("lgqq","body=====33333=");
//        TagAliasOperatorHelper.getInstance().onAliasOperatorResult(context,jPushMessage);super.onAliasOperatorResult(context, jPushMessage);}
}

5、配置receiver

6、权限,

<uses-permission android:name="com.tianxin.maient.liteapp.permission.JPUSH_MESSAGE" />//自己的包名
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<receiver android:name="com.tianxin.jpushs.MyJPushReceiver"android:enabled="true"><intent-filter android:priority="1000"><action android:name="cn.jpush.android.intent.REGISTRATION" /><action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" /><action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" /><action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" /><action android:name="cn.jpush.android.intent.NOTIFICATION_CLICK_ACTION" /><action android:name="cn.jpush.android.intent.CONNECTION" /><category android:name="com.tianxin.mapclient.liteapp" />//自己的包名</intent-filter></receiver><receiver android:name="com.tianxin.jpushs.MyJPushMessageReceiver"><intent-filter><action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" /><category android:name="com.tianxin.mapclient.liteapp"></category>//自己的包名</intent-filter>
</receiver>

7、实例化

JPushInterface.init(context);

8、设置别名

     JPushInterface.setAlias(this, //上下文对象JPushUtil.getDeviceId(MainActivity.this), //别名new TagAliasCallback() {//回调接口,i=0表示成功,其它设置失败@Overridepublic void gotResult(int i, String s, Set<String> set) {Log.d("alias", "set alias result is" + i);}});

9、去极光发送通知,即可收到通知

在线解决bug:qq1085220040

Android 10分钟集成极光推送相关推荐

  1. 极光推送 简书android,(Android)react-native集成极光推送

    在Android中使用reactnative集成极光推送步骤如下: (1)在AndroidManifest中声明网络权限,获取包名到极光推送官网添加应用,获取AppKey,该key需要注册到应用中以获 ...

  2. Android第三方SDK集成 —— 极光推送

    前言: 本文前篇,可以帮助朋友们快速集成极光推送.本文后篇,是我自己项目实践的一些总结和心得,应该对读者们还是很有参考价值的,相信读完这篇文章,你会对极光推送有更加深入的理解,而不仅仅只是会集成而已. ...

  3. Android集成极光推送踩坑(二)升级篇

    转载请标明出处 http://blog.csdn.net/mohan6/article/details/74133186 本文作者:[默寒的博客] 前言 前段时间针对集成极光推送写了篇文章( Andr ...

  4. React-Native集成极光推送(Android和IOS)

    React-Native集成极光推送的具体流程如下: 本文选取的是极光官方维护的react-native推送插件,github地址:https://github.com/jpush/jpush-rea ...

  5. Java中集成极光推送实现给Android提送消息通知(附代码下载)

    场景 Android中集成极光推送实现推送消息通知与根据别名指定推送附示例代码下载: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details ...

  6. 极光推送 android 最新,Android——快速集成极光推送-Go语言中文社区

    集成极光推送 1,首先肯定是注册,添加应用 2,开始自动集成比手动集成简单第一步 在 build.gradle defaultConfig { multiDexEnabledtrue applicat ...

  7. uniapp轻松集成极光推送自定义消息+通知 Android极光 IOS极光 两行代码集成极光SDK

    ###[前言] 极光推送(JPush)在为开发者提供基础推送服务的同时,还提供了用户精准标签.用户分群.地理围栏.应用内消息.智能发送策略.智能促活等服务能力,可有效提升消息的送达率.展示率和点击率, ...

  8. Android之集成极光推送

    安卓端集成极光推送是很常见的,极光推送的简单高效性适合很多想要集成推送的APP,如果你要自己装逼,也可以自己写推送,只要想做都是可以的. 第一步.Gradle配置(Module的build.gradl ...

  9. 三分钟帮你集成极光推送——和那些可能你不知道的事

    本文简介:本文前篇,可以帮助朋友们快速集成极光推送.本文后篇,是我自己项目实践的一些总结和心得,应该对读者们还是很有参考价值的,相信读完这篇文章,你会对极光推送有更加深入的理解,而不仅仅只是会集成而已 ...

最新文章

  1. ubuntu如何修改字符集编码
  2. 注意!我们熟知的“摩尔定律”被废了...
  3. 联想笔记本电脑无法在编码中直接使用Home和End快捷键需要+fn解决方案
  4. Spark的Dataset操作
  5. python-if判断
  6. Unity3D开发之unity和js通信交互
  7. vc与三菱PLC编程口通信C语言源代码,三菱PLC通讯与编程实例!
  8. Zmodem安装,拖拽的方式通过shell命令界面实现windows和linux之间的文件互传
  9. CentOS7--安装谷歌浏览器--详细步骤
  10. ASM的普通盘转AFD
  11. 如何卸载手机系统自带应用(无需root)?【亲测有用】
  12. mysql分列查询,SQL计算符合条件行数量,并分列显示,怎么做
  13. 如何删除在Excel中存在的无效的链接呢
  14. UI设计学习路线是什么?
  15. K8S中使用显卡GPU(N卡) —— 筑梦之路
  16. 欧几里得算法和扩展欧几里得算法——杨子曰数学
  17. 016--JLE JNG(小于等于)
  18. CSDN 还是一个不错的技术社区
  19. 旅行照片剪辑--环青海湖篇
  20. 关于架空光缆你知道多少?

热门文章

  1. [css] 举例说明你对相邻兄弟选择器的理解
  2. 前端学习(2567):指令的本质
  3. 前端学习(1809):前端调试之微博头部开发
  4. oracle之单行函数之多表查询
  5. 前端学习(1405):多人管理25node.js—安装bcrypt出现错误的解决办法
  6. 前端学习(1149):变量let02
  7. 前端学习(970):fastclick插件使用
  8. 前端学习(498):水平居中布局得第一种方式
  9. 前端学习(483):html之常用标签
  10. 57javabean简介