进行到这里就可以接收到通知了,但是如果你还想根据接收的消息做点什么

step8:
public class MyReceiver extends BroadcastReceiver {private static final String TAG = "MyReceiver";private NotificationManager nm;@Overridepublic void onReceive(Context context, Intent intent) {if (null == nm) {nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);}Bundle bundle = intent.getExtras();
//        Log.d(TAG, "onReceive - " + intent.getAction() + ", extras: " + AndroidUtil.printBundle(bundle));if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {Log.d(TAG, "JPush 用户注册成功");} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {Log.d(TAG, "接受到推送下来的自定义消息");} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {Log.d(TAG, "接受到推送下来的通知");receivingNotification(context,bundle);} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {Log.d(TAG, "用户点击打开了通知");openNotification(context,bundle);} else {Log.d(TAG, "Unhandled intent - " + intent.getAction());}}private void receivingNotification(Context context, Bundle bundle){String title = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);Log.d(TAG, " title : " + title);String message = bundle.getString(JPushInterface.EXTRA_ALERT);Log.d(TAG, "message : " + message);String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);Log.d(TAG, "extras : " + extras);}private void openNotification(Context context, Bundle bundle){String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);String myValue = "";try {JSONObject extrasJson = new JSONObject(extras);myValue = extrasJson.optString("myKey");} catch (Exception e) {Log.w(TAG, "Unexpected: extras is not a valid json", e);return;}Log.d(TAG, "myValue : " + myValue);if (TYPE_THIS.equals(myValue)) {Intent mIntent = new Intent(context, ThisActivity.class);mIntent.putExtras(bundle);mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);context.startActivity(mIntent);} else if (TYPE_ANOTHER.equals(myValue)){Intent mIntent = new Intent(context, AnotherActivity.class);mIntent.putExtras(bundle);mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);context.startActivity(mIntent);}}
}

step9:最后别忘了在清单中注册

    <!--极光推送接收消息--><receiverandroid:name="com.psm.admininstrator.lele8teach.MyReceiver"android:exported="false"android:enabled="true"><intent-filter><action android:name="cn.jpush.android.intent.REGISTRATION" /> <!--Required  用户注册SDK的intent--><action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" /> <!--Required  用户接收SDK消息的intent--><action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" /> <!--Required  用户接收SDK通知栏信息的intent--><action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" /> <!--Required  用户打开自定义通知栏的intent--><action android:name="cn.jpush.android.intent.CONNECTION" /><!-- 接收网络变化 连接/断开 since 1.6.3 --><category android:name="com.psm.admininstrator.lele8teach" /></intent-filter></receiver></application>

原博客地址:https://blog.csdn.net/jinjianghai/article/details/80336099

转载于:https://www.cnblogs.com/wzqnxd/p/10511607.html

极光推送配置(Android Studio),亲测有效相关推荐

  1. 极光推送在Android端的集成

    这个周末,是最颓废的一个周末了.工作以来,基本每个周末都会学习点知识或者总结些东西.这个周末,身体不是很舒服,结果躺床上打了两天农药,也没有写博客.今天周一,正好我工作不忙,把上周末的博客补上.今天的 ...

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

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

  3. 极光小课堂 | 极光推送之 Android 客户端使用指南——基础篇

    " 本文中涉及到的所有代码现已在 Github 上开源,地址:https://github.com/xuexiangjys/JPushSample" 01 前言 - 极光推送是国内 ...

  4. 极光推送配置不成功的原因

    极光推送配置不成功的原因有很多种,一般情况下只要设置了debug模式,都会以通知栏的形式来提示问题的所在. 但是有时候设置了debug模式,也没有错误提示,从极光后台推送的话,会提示没有注册用户. 这 ...

  5. android 极光推送测试,Android 3分钟带你集成极光推送

    话不多说 首先申请极光的账号,(官方地址:https://www.jiguang.cn) 1561710140829.png 登录完成之后,先看到这个地方 ,我个人比较喜欢用旧版本,这里点击旧版 15 ...

  6. java集成极光推送实现Android的消息推送

    1.极光推送的思路就是,每一个app都有一个AppKey和Master Secret,这两个值是唯一的,也就是用来标识App的唯一信息,具体怎么获取,去看极光推送官网文档,这里就不在讲解.我们在极光开 ...

  7. android 极光推送混淆,android 混淆文件的编写(proguard-rules.pro)

    压缩级别 -optimizationpasses 5 -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -dontpreveri ...

  8. android极光推送 小米,android 接极光推送厂商通道,华为 小米 VIVO OPPO

    我首先接入极光推送,然后才来接厂商通道, 需要先接极光推送的看我另外一边帖子, 1   在根目录的build.gradle buildscript{ repositories{ google() jc ...

  9. android极光推送声音,Android 极光推送JPush---自定义提示音

    public classMyReceiver extends BroadcastReceiver {private static final String TAG = MyReceiver.class ...

最新文章

  1. Swift监听网络状态
  2. python语言的实验心得体会范文_实验报告个人心得体会范文
  3. C++内存分配方式详解——堆、栈、自由存储区、全局/静态存储区和常量存储区...
  4. 一窥 ARM 的 AI 处理器
  5. 安装sql2017时提示Polybase 要求安装Oracle JRE 7更新51 (64位)或更高版本”规则失败...
  6. 热力地图高德_《高德地图》城市热力图开启查看方法
  7. 微信文章编辑的html在哪里,微信公众号的文章编辑界面在哪里?怎么编辑排版? | 微信公众号指南...
  8. 八款值得尝试的精美的 Linux 发行版(2017 版)
  9. Linux C语言学习day11:递归与结构体
  10. Python制作古诗生成器
  11. iOS 第四天之ViewController
  12. Vagrant安装和使用
  13. 如何认识和投身 Web 3.0?
  14. CrystalDiskInfo硬盘检测工具 标准版及萌妹版
  15. 水星路由app服务器无响应,手机登录不了水星路由器的管理界面解决方法
  16. 短视频剪辑如何正确把握“节奏感”,三个小技巧助你快慢有序
  17. TCL双引号 花括号 中括号
  18. python随机数产生100个整数(0-100),统计出现次数最多的数字.
  19. spring security
  20. 输入法不见了怎么办?

热门文章

  1. pb mdi窗口多sheet_Filecoin奖励测试网8月3日开启,主网启动窗口:8月31日至9月21日...
  2. 4位快速加法器设计_芯片的诞生,奇妙之旅,从RTL代码到真实芯片是怎么设计制造的...
  3. pmp考试用计算机,PMP是计算机类考试吗
  4. php的优势和背景,CSS_CSS 多图片融合背景定位的应用于优缺点分析,1. 关键字, 例如: background-positio - phpStudy...
  5. java语言程序设计考点_计算机二级考试Java语言程序设计考点:关键字
  6. 离线人脸属性分析_最新开源 | 人脸识别应用套件:毫秒级离线识别 适用多类场景...
  7. FPGA的LVDS电平以及LVDS25电平能在HR Bank上使用吗?
  8. Vivado中Debug的用法总结
  9. Guass消去法求解线性方程组
  10. Visual Studio 2017 15.8概览