第十六章:自定义push notification sound
前面一节已经讲过如何在ionic中集成jpush,这样我们的hybrid app在部署到ios或者android上面的时候,就可以接收通知了。如果不满足系统自带的声音,可以通过一些方式来播放自定义的通知铃声。需要严格按照下面的步骤来操作。
ios:
主要思路:在发送push notification的时候指定sound文件名,并且在xcode编译ios的时候把指定的sound文件放到resource文件夹中;ionic中不需要做任何的改动。
- 编译工程:ionic build ios
- 使用xcode打开工程
- 把铃声文件放到resource文件夹中
- 安装到Iphone上
- 使用jpush console测试(http://www.jpush.cn)
android:
主要思路:在接收到jpush的notification的时候,取消下一步的操作;转而使用android本身的NotificationBuilder来处理notification(需要在android sudio中指定声音文件),可自定义声音、icon等信息。
- ionic build android
- 使用android studio打开工程
- 在res/raw文件夹下面添加sound文件
- 重写myreceiver中的handlingNotificationReceive,使之看起来如下:
private void handlingNotificationReceive(Context context, Intent intent) {
Log.i(TAG, "---------------- handlingNotificationReceive"); Intent launch = context.getPackageManager().getLaunchIntentForPackage(
context.getPackageName());
launch.addCategory(Intent.CATEGORY_LAUNCHER);
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); String title = intent.getStringExtra(JPushInterface.EXTRA_NOTIFICATION_TITLE);
JPushPlugin.notificationTitle = title; String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
JPushPlugin.notificationAlert = alert; Map<String, Object> extras = getNotificationExtras(intent);
JPushPlugin.notificationExtras = extras; NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification.Builder mBuilder = new Notification.Builder(
context)
.setSmallIcon(R.drawable.icon)
.setContentTitle(title)
.setContentText(alert); Intent notificationIntent = new Intent(context,
MainActivity.class);
PendingIntent intent1 = PendingIntent.getActivity(context, 0,
notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); mBuilder.setContentIntent(intent1);
Uri uri=Uri.parse("android.resource://" + context.getPackageName() + "/" +R.raw.csound);
mBuilder.setSound(uri);
Notification notification = mBuilder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification); // JPushPlugin.transmitNotificationReceive(title, alert, extras);
}
- 安装到android手机上
- 使用jpush console进行测试(http://www.jpush.cn)
参考:
IOS: local notifications and remote notifications(known as push notifications)
IOS(solution): customize sounds in push notifications
IOS: playing system sound without importing any sounds
android: stack overflow, how to custom push notifications
android: how to custom push notifications sound base on pushwoosh
android(solution): custom push notifications based on jpush api
第十六章:自定义push notification sound的更多相关文章
- Gradle 1.12用户指南翻译——第二十六章. War 插件
其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Github上的地址: https://g ...
- Gradle 1.12用户指南翻译——第三十六章. Sonar Runner 插件
本文由CSDN博客万一博主翻译,其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Githu ...
- 【C++】《C++ Primer 》第十六章
第十六章 模板与泛型编程 面向对象编程和泛型编程都能处理在编写程序时不知道类型的情况. OOP能处理类型在程序允许之前都未知的情况. 泛型编程在编译时就可以获知类型. 一.定义模板 模板:模板是泛型编 ...
- 《Linux命令行与shell脚本编程大全》 第十六章 学习笔记
第十六章:创建函数 基本的脚本函数 创建函数 1.用function关键字,后面跟函数名 function name { commands } 2.函数名后面跟空圆括号,标明正在定义一个函数 name ...
- Gradle 1.12 翻译——第十六章. 使用文件
有关其它已翻译的章节请关注Github上的项目:https://github.com/msdx/gradledoc/tree/1.12,或訪问:http://gradledoc.qiniudn.com ...
- 第十六章——处理锁、阻塞和死锁(3)——使用SQLServer Profiler侦测死锁
原文:第十六章--处理锁.阻塞和死锁(3)--使用SQLServer Profiler侦测死锁 前言: 作为DBA,可能经常会遇到有同事或者客户反映经常发生死锁,影响了系统的使用.此时,你需要尽快侦测 ...
- CSS3秘笈复习:十三章&十四章&十五章&十六章&十七章
第十三章 1.在使用浮动时,源代码的顺序非常重要.浮动元素的HTML必须处在要包围它的元素的HTML之前. 2.清楚浮动: (1).在外围div的底部添加一个清除元素:clear属性可以防止元素包围浮 ...
- 《HTTP 权威指南》笔记:第十六章&第十七章 国际化、内容协商与转码
<HTTP 权威指南>笔记:第十六章 国际化 客户端通过在请求报文中的 Accept-Language 首部和 Accept-Charset 首部来告知服务器:“我理解这些语言.”服务器通 ...
- “全栈2019”Java多线程第二十六章:同步方法生产者与消费者线程
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...
随机推荐
- go的Type switch是一个switch语句么?
相信这样的语句在go中大家见的很多 switch t := arg.(type) { default: fmt.Printf("unexpected type %T\n", t) ...
- Mybatis-generator逆向工程
$.Mybatis-generator介绍 MyBatis Generator(MBG)是MyBatis MyBatis 和iBATIS的代码生成器.它将为所有版本的MyBatis以及版本2.2.0之 ...
- windows下安装newman
1.下载安装node.js,下载地址::https://nodejs.org/en/download/,这里我下载的为v10.15.0-x64.msi,下载后直接安装即可,安装完后可输入node -v ...
- 20165219 学习基础与C语言基础调查
学习基础与C语言基础调查 你有什么技能比大多数人要好? 因为不知道其他人的具体情况,我只能说,我比较擅长钢琴,素描,国画,这也是小时候掌握的比较好的技能. 针对这个技能的获取有什么成功的经验 小时候学 ...
- WPF 动态更换模板
Window x:Class="模板选择器.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml ...
- win7 64位环境下,为python2.7 安装pip
第一步: 安装python并配置好环境变量 参见:http://blog.csdn.net/donggege214/article/details/52062855 第二步: 下载setuptools ...
- luoguP2982 [USACO10FEB]慢下来Slowing down
https://www.luogu.org/problemnew/show/P2982 这题你写个树剖当然可以做,但是我们还有一种更简单的方法,使用 dfs 序 + 树状数组即可 考虑一只牛到了自己的 ...
- spark执行例子eclipse maven打包jar
首先在eclipse Java EE中新建一个Maven project具体选项如下 点击Finish创建成功,接下来把默认的jdk1.5改成jdk1.8 然后编辑pom.xml加入spark-cor ...
- Python3之时间模块time & datetime & calendar
一. 简介 python 提供很多方式处理日期与时间,转换日期格式是一个常见的功能. 时间元组:很多python函数用一个元组装起来的9组数字处理时间. python中时间日期格式化符号: %y 两位 ...
- 3 hql语法及自定义函数(含array、map讲解) + hive的java api
本博文的主要内容如下: .hive的详细官方手册 .hive支持的数据类型 .Hive Shell .Hive工程所需依赖的jar包 .hive自定义函数 .分桶4 .附PPT hiv ...