前面一节已经讲过如何在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. 解决chrome浏览器无法得到window.showModalDialog返回值的问题

    父页面处理: function ProductList() {   var TypeID = window.document.getElementById("Type").valu ...

  2. wpf附加属性理解

    WPF附加属性 http://www.cnblogs.com/tianyou/archive/2012/12/27/2835670.html WPF属性(二)附加属性 http://blog.csdn ...

  3. java jeesite.properties配置文件属性提取

    package com.thinkgem.jeesite.common.config; import java.io.UnsupportedEncodingException; import java ...

  4. Lua入门(一)

    嵌入式语言 作为一门扩展式语言,Lua 没有 "main" 程序的概念: 它只能 嵌入 一个宿主程序中工作, 该宿主程序被称为 被嵌入程序 或者简称 宿主 . 宿主程序可以调用函数 ...

  5. [转载] C++ namespaces 使用

    原地址:http://blog.sina.com.cn/s/blog_986c99d601010hiv.html 命名空间(namespace)是一种描述逻辑分组的机制,可以将按某些标准在逻辑上属于同 ...

  6. k8s(未完待续)

    K8s简介Kubernetes(k8s)是自动化容器操作的开源平台,这些操作包括部署,调度和节点集群间扩展. 使用Kubernetes可以  自动化容器的部署和复制  随时扩展或收缩容器规模  将容器 ...

  7. 设置使用的python版本

    一.查看当前使用的python版本,或设置使用的python版本 二.python2中默认使用ASCII码,无法识别中文,报错如图,解决办法,设置字符集为utf-8

  8. 洛谷P4557 [JSOI2018]战争(闵可夫斯基和+凸包)

    题面 传送门 题解 看出这是个闵可夫斯基和了然而我当初因为见到这词汇是在\(shadowice\)巨巨的\(Ynoi\)题解里所以压根没敢学-- 首先您需要知道这个 首先如果有一个向量\(w\)使得\ ...

  9. 洛谷P2775 机器人路径规划问题

    传送门 题解 至今没看懂这深搜怎么写的…… //minamoto #include<iostream> #include<cstdio> #include<cstring ...

  10. 三种timer控件的简单实例

    .system.windows.forms .system.threading.timer .system.timers.timer using System; using System.Collec ...