官方文档未写如何自定义声音https://docs.jiguang.cn/jpush/client/Android/android_sdk/

但可以看到 客户端设置通知栏样式

可以定义样式,那么可以禁用极光的声音,收到通知就播放一个声音就好:

禁用:

// 极光JPushInterface.setDebugMode(IS_DEBUG);JPushInterface.init(this);BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(this);builder.statusBarDrawable = R.drawable.icon_apk_fangzhi;builder.notificationFlags = Notification.FLAG_AUTO_CANCEL//| Notification.FLAG_SHOW_LIGHTS; // 设置为自动消失和呼吸灯闪烁builder.notificationDefaults = ////Notification.DEFAULT_SOUND | // 设置为铃声Notification.DEFAULT_VIBRATE | // 设置为、震动Notification.DEFAULT_LIGHTS; // 设置为呼吸灯闪烁JPushInterface.setPushNotificationBuilder(1, builder);

在广播里播放SoundHelper.get().palyOrder();:

@Overridepublic void onReceive(Context context, Intent intent) {Bundle bundle = intent.getExtras();if (null == bundle) {return;}Log.d(TAG, "[MyReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle));if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);Log.d(TAG, "[MyReceiver] 接收Registration Id : " + regId);// send the Registration Id to your server...} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {Log.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE));processCustomMessage(context, bundle);} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {SoundHelper.get().palyOrder();

SoundHelper类:

package com.--.comm.helper;import android.annotation.SuppressLint;import android.content.Context;import android.media.AudioManager;import android.media.SoundPool;import android.os.Build;import android.view.View;//SoundPool.play(int soundID, float leftVolume, float rightVolume, int priority, int loop, float rate)//参数依次是: //soundID:Load()返回的声音ID号 //leftVolume:左声道音量设置 //rightVolume:右声道音量设置 //priority:指定播放声音的优先级,数值越高,优先级越大。 //loop:指定是否循环:-1表示无限循环,0表示不循环,其他值表示要重复播放的次数 //rate:指定播放速率:1.0的播放率可以使声音按照其原始频率,而2.0的播放速率,可以使声音按照其 //原始频率的两倍播放。如果为0.5的播放率,则播放速率是原始频率的一半。播放速率的取值范围是0.5至2.0。public class SoundHelper {private SoundPool soundPool;private int idSure;private int idCanel;private int idOrder;private static SoundHelper helper;@SuppressLint("NewApi")@SuppressWarnings("deprecation")public SoundHelper() {Context context = Application.mContext;if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {SoundPool.Builder spb = new SoundPool.Builder();spb.setMaxStreams(10);// spb.setAudioAttributes(null); // 转换音频格式soundPool = spb.build(); // 创建SoundPool对象} else {soundPool = new SoundPool(2, AudioManager.STREAM_SYSTEM, 5);}idSure = soundPool.load(context, R.raw.h_sure_open, 1);idCanel = soundPool.load(context, R.raw.h_cancel_back, 1);idOrder = soundPool.load(context, R.raw.order, 1);}public static SoundHelper get() {if (null == helper) {helper = new SoundHelper();}return helper;}public void palyOrder() {soundPool.play(idOrder, 1, 1, 10, 0, 1);}public void palySure() {if (BaseApplication.get().isOpenSoundBtn() && DefaultShared.isH()) {soundPool.play(idSure, 1, 1, 0, 0, 1);}}public void palyCancel() {if (BaseApplication.get().isOpenSoundBtn() && DefaultShared.isH()) {soundPool.play(idCanel, 1, 1, 0, 0, 1);}}}

IOS自定义声音比较简单:

极光后台填入声音文件名(后台代码调用多一个参数而已),然后把声音文件放在工程里即可



要实现不同的通知对不同的声音,安卓要自定义字段解决。

更多相关文章

  1. Android开发实战使用(VR技术实现360°全景视频播放功能)
  2. android实现在线播放流媒体
  3. android之帧动画实现
  4. android音乐播放器开发 SweetMusicPlayer 播放本地音乐
  5. Android音乐播放器-图片素材准备及布局
  6. 解决vlc-android播放http视频退出问题
  7. 【Android】- MediaPlayer错误之MediaPlayer start called in st
  8. Android(安卓)Jamendo开源在线音乐播放器源码分析七 数据缓存和
  9. Android(安卓)播放 Gif 图片控件

随机推荐

  1. Gradle,*.jar,*aar
  2. 如何让android不运行默认的MainActivity.
  3. Windows下用Git下载android源码
  4. Android使用AsyncTask下载图片,最好使用We
  5. Android 集成flutter
  6. android studio里面的svn基本使用
  7. Android 简单计算器实现
  8. Android手势翻页效果
  9. Android的富文本功能
  10. Android SmartRefreshLayout下拉刷新上拉