前面一节已经讲过如何在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: list of system sounds

IOS: playing system sound without importing any sounds

online media convertor

android: push notifications

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的更多相关文章

  1. Gradle 1.12用户指南翻译——第二十六章. War 插件

    其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Github上的地址: https://g ...

  2. Gradle 1.12用户指南翻译——第三十六章. Sonar Runner 插件

    本文由CSDN博客万一博主翻译,其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Githu ...

  3. 【C++】《C++ Primer 》第十六章

    第十六章 模板与泛型编程 面向对象编程和泛型编程都能处理在编写程序时不知道类型的情况. OOP能处理类型在程序允许之前都未知的情况. 泛型编程在编译时就可以获知类型. 一.定义模板 模板:模板是泛型编 ...

  4. 《Linux命令行与shell脚本编程大全》 第十六章 学习笔记

    第十六章:创建函数 基本的脚本函数 创建函数 1.用function关键字,后面跟函数名 function name { commands } 2.函数名后面跟空圆括号,标明正在定义一个函数 name ...

  5. Gradle 1.12 翻译——第十六章. 使用文件

    有关其它已翻译的章节请关注Github上的项目:https://github.com/msdx/gradledoc/tree/1.12,或訪问:http://gradledoc.qiniudn.com ...

  6. 第十六章——处理锁、阻塞和死锁(3)——使用SQLServer Profiler侦测死锁

    原文:第十六章--处理锁.阻塞和死锁(3)--使用SQLServer Profiler侦测死锁 前言: 作为DBA,可能经常会遇到有同事或者客户反映经常发生死锁,影响了系统的使用.此时,你需要尽快侦测 ...

  7. CSS3秘笈复习:十三章&十四章&十五章&十六章&十七章

    第十三章 1.在使用浮动时,源代码的顺序非常重要.浮动元素的HTML必须处在要包围它的元素的HTML之前. 2.清楚浮动: (1).在外围div的底部添加一个清除元素:clear属性可以防止元素包围浮 ...

  8. 《HTTP 权威指南》笔记:第十六章&第十七章 国际化、内容协商与转码

    <HTTP 权威指南>笔记:第十六章 国际化 客户端通过在请求报文中的 Accept-Language 首部和 Accept-Charset 首部来告知服务器:“我理解这些语言.”服务器通 ...

  9. “全栈2019”Java多线程第二十六章:同步方法生产者与消费者线程

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...

随机推荐

  1. scala冒泡排序

    scala冒泡排序: object Maopao { def main(args: Array[String]) { val list = List(1, 23, 432, 10, 23, 42, 3 ...

  2. 八、Node.js-http模块

    JS代码如下: /* 如果我们使用PHP来编写后端的代码时,需要Apache 或者 Nginx 的HTTP 服务器,并配上 mod_php5 模块和php-cgi,来处理客户端的请求相应. 不过对 N ...

  3. Kotlin 函数和函数表达式

    学习了kotlin 的控制. 其中最为强大的是各种控制可以直接作为表达式来使用. 那么在kotlin中,函数也是可以作为表达式来使用. 而且kotlin中函数的创建方式有很多方式. 第一种: 传统创建 ...

  4. django中博客后台将图片上传作为用户头像

    添加上传目录 # 如果不添加上传目录,仍然可以上传成功,默认为project目录,如果models.py定义了upload_to="目录名称",则会上传到"project ...

  5. 20165219 《Java程序设计》实验一(Java开发环境的熟悉)实验报告

    20165219 <Java程序设计>实验一(Java开发环境的熟悉)实验报告 一.实验报告封面 课程:Java程序设计 班级:1652班 姓名:王彦博 学号:20165219 成绩: 指 ...

  6. C# winform调用类似按钮点击的事件时自带参数该怎么写

    //按钮事件 private void btn_Click(object sender, EventArgs e) {} //自己的函数 private void myFunc() { //程序中其他 ...

  7. 条目十四《使用reserve来避免不必要的重新分配》

    条目十四<使用reserve来避免不必要的重新分配> 使用vector和string的插入元素的时候,我们是不用担心内存问题的(只要不超过容器的max_size).因为底层有分配子管理内存 ...

  8. ob系列函数归纳

     输出控制函数(output control函数) flush — 刷新输出缓冲ob_clean — 清空(擦掉)输出缓冲区ob_end_clean — 清空(擦除)缓冲区并关闭输出缓冲ob_end_ ...

  9. 剩下的树 THU 机试

    链接:https://www.nowcoder.com/questionTerminal/f5787c69f5cf41499ba4706bc93700a2来源:牛客网 有一个长度为整数L(1<= ...

  10. STM32F0 中 ADC 多通道转换结果相同的问题

    前言 前段时间调试 STM32F030 的 ADC,在多通道转换时遇到了奇怪的问题,使用官方的例程和库函数连续转换多个 ADC 通道,得到的几个通道的结果是一样的,解决办法参考了 关于STM32F0系 ...