极光推送(二)接收通知
步骤(分为两步)
一.设置通知栏样式(如果不设置则默认使用自带的),这里官方给了三种方式:
1.基础(定制声音、震动、闪灯等 Notification 样式):
BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(MainActivity.this); builder.statusBarDrawable = R.drawable.jpush_notification_icon; builder.notificationFlags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS; //设置为自动消失和呼吸灯闪烁 builder.notificationDefaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS; // 设置为铃声、震动、呼吸灯闪烁都要 //注意这里的 1 ,以后会有用 JPushInterface.setPushNotificationBuilder(1, builder);
2.定制带按钮的Notification样式(3.0.0及以上版本sdk才支持该样式,且该样式在某些与Android原生系统有差异的机型上无法正常显示):
MultiActionsNotificationBuilder builder = new MultiActionsNotificationBuilder(PushSetActivity.this); //添加按钮,参数(按钮图片、按钮文字、扩展数据) builder.addJPushAction(R.drawable.jpush_ic_richpush_actionbar_back, "first", "my_extra1"); builder.addJPushAction(R.drawable.jpush_ic_richpush_actionbar_back, "second", "my_extra2"); builder.addJPushAction(R.drawable.jpush_ic_richpush_actionbar_back, "third", "my_extra3"); //注意这里设置的2,以后会有用 JPushInterface.setPushNotificationBuilder(2, builder);
3.高级自定义:
CustomPushNotificationBuilder builder = new CustomPushNotificationBuilder(this, R.layout.customer_notitfication_layout, R.id.icon, R.id.title, R.id.text); // 指定定制的 Notification Layout builder.statusBarDrawable = R.mipmap.ic_launcher; // 指定最顶层状态栏小图标 builder.layoutIconDrawable = R.mipmap.flag; // 指定下拉状态栏时显示的通知图标,同时也注意这里的3,因为能否显示自定义的这些通知样式全靠这些标记 JPushInterface.setPushNotificationBuilder(3, builder);
二.如何显示你所设置的通知:
通过极光推送的后台发送通知你会发现你所设置的样式不起作用,那么如何让它起作用呢?这里有两种方式可以实现:
1.通过配置后台数据:
1).在极光推送后台发送通知时点击可选设置按钮
2).在通知栏样式编号那里填写上面我所强调需要注意的标记,即可显示你设置的通知栏样式
2.通过代码修改默认通知栏样式:
CustomPushNotificationBuilder builder = new CustomPushNotificationBuilder(this, R.layout.customer_notitfication_layout, R.id.icon, R.id.title, R.id.text); // 指定定制的 Notification Layout builder.statusBarDrawable = R.mipmap.ic_launcher; // 指定最顶层状态栏小图标 builder.layoutIconDrawable = R.mipmap.flag; // 指定下拉状态栏时显示的通知图标 JPushInterface.setPushNotificationBuilder(1, builder); JPushInterface.setDefaultPushNotificationBuilder(builder);
三.获取通知的信息
1.编写接收消息的Receiver
public class JiguangReceiver extends BroadcastReceiver { private NotificationManager nm; @Override public void onReceive(Context context, Intent intent) { if (null == nm) { nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); } Bundle bundle = intent.getExtras(); if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) { openNotification(context,bundle); } } // 点击通知栏信息启动Activity private void openNotification(Context context, Bundle bundle) { Intent mIntent = new Intent(context, Test1Activity.class); mIntent.putExtras(bundle); mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(mIntent); } }
2.在AndroidManifest.xml文件中注册Receiver
<receiver android:name=".JiguangReceiver" android:enabled="true"> <intent-filter> <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.itfitness.jiguang" /> </intent-filter> </receiver>
3.在点击通知打开的Activity中展示信息
public class Test1Activity extends AppCompatActivity { private TextView textView; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test_layout); textView = findViewById(R.id.tv); Bundle extras = getIntent().getExtras(); textView.setText(extras.getString(JPushInterface.EXTRA_EXTRA)); } }
四.效果展示
1.添加字段
个人技术博客:https://myml666.github.io
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Unity获取Android平台音量
图片.png https://www.cnblogs.com/Jason-c/p/7766021.html http://blog.csdn.net/tdstds/article/details/25533291 using UnityEngine; using System.Collections; using UnityEngine.UI; public class AndroidAudio : MonoBehaviour { private const string currentVolume = "getStreamVolume"; //当前音量 private const string maxVolume = "getStreamMaxVolume"; //最大音量 private const int STREAM_VOICE_CALL = 0; // 通话音量 private const int STREAM_SYSTEM = 1; // 系统音量 private const int STREAM_RING = 2; // 铃声音量 private const int ST...
- 下一篇
Android 实现锚点定位
原文链接:https://mp.weixin.qq.com/s/EYyTBtM9qCdmB9nlDEF-3w 相信做前端的都做过页面锚点定位的功能,通过<a href="#head"> 去设置页面内锚点定位跳转。 本篇文章就使用tablayout、scrollview来实现android锚点定位的功能。 效果图: 实现思路 1、监听scrollview滑动到的位置,tablayout切换到对应标签 2、tablayout各标签点击,scrollview可滑动到对应区域 自定义scrollview 因为我们需要监听到滑动过程中scrollview的滑动距离,自定义scrollview通过接口暴露滑动的距离。 public class CustomScrollView extends ScrollView { public Callbacks mCallbacks; public CustomScrollView(Context context) { super(context); } public CustomScrollView(Context context, Attri...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
-
Docker使用Oracle官方镜像安装(12C,18C,19C)
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- CentOS8编译安装MySQL8.0.19
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- MySQL8.0.19开启GTID主从同步CentOS8
- CentOS7,8上快速安装Gitea,搭建Git服务器
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
推荐阅读
最新文章
- CentOS6,CentOS7官方镜像安装Oracle11G
- Windows10,CentOS7,CentOS8安装Nodejs环境
- CentOS8编译安装MySQL8.0.19
- SpringBoot2整合Thymeleaf,官方推荐html解决方案
- 设置Eclipse缩进为4个空格,增强代码规范
- CentOS7,8上快速安装Gitea,搭建Git服务器
- Windows10,CentOS7,CentOS8安装MongoDB4.0.16
- CentOS7安装Docker,走上虚拟化容器引擎之路
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题