前面一节已经讲过如何在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. cmake笔记

    注:cmake .   当前文件夹(一个点)   cmake .. 父目录(两个点) 例子一 一个经典的C程序,如何用cmake来进行构建程序呢? //main.c #include <stdi ...

  2. delphi Post数据到网页

    var http: TIdHttp; sendtoserver: TStringStream; str: string; begin http := TIdHttp.Create(); // 创建 h ...

  3. RobotFramework添加自定义关键字实战

    背景: 此篇文章是上一篇博客python的requests库怎么发送带cookies的请求的后续,上一篇只是使用python脚本调试通过了,接下来要把我们的方法封装为关键字,在RF中调用. 实施: 一 ...

  4. [Algorithm]图

    一.图的算法 邻接矩阵表示的数据结构 1 #define INFINITY INT_MAX // 无穷大 2 #define MAX_VERTEX_NUM 20 // 限制顶点最大数值为20个 3 # ...

  5. shell和matlab之间的参数传递

        shell和matlab之间的参数传递比shell和Python之间的参数传递要简单,在matlab程序中(以.m脚本文件为例,其他程序如函数等未测试)不需要进行任何配置,直接使用即可,见下面 ...

  6. mybatis 学习笔记(三):mapper 代理开发 dao 层

    mybatis 学习笔记(三):mapper 代理开发 dao 层 优势 通过使用mapper 代理,我们可以不需要去编写具体的实现类(使用 getMapper() 方法自动生成),只需编写接口即可, ...

  7. 解决CentOS查询不到ip

    问题:登陆操作系统,输入ip addr 也可以输入ifconfig查看ip,发现ens33目录中没有inet属性 解答:查看ens33的网卡配置: vi /etc/sysconfig/network- ...

  8. flex 实例Demo

    Flex 页面布局 很方便 快捷 <!DOCTYPE html> <html lang="en"> <head> <meta charse ...

  9. Android Activity实例应用(选择QQ头像)

    1.效果图 点击button,跳转到页面2 选择需要的头像,自动返回 3.XML文件布局 页面1 <?xml version="1.0" encoding="utf ...

  10. [USACO12FEB]牛的IDCow IDs 一题多解(求二进制中有k个1 ,第n大的数)

    题目: FJ给他的奶牛用二进制进行编号,每个编号恰好包含K 个"1" (1 <= K <= 10),且必须是1开头.FJ按升序编号,第一个编号是由K个"1&q ...