友盟推送支持自定义通知声音,在Android8.0以下,就很简单:

在您项目的res/raw/下放置命名为umeng_push_notification_default_sound。若无此文件,则默认使用系统的Notification声音

在Android8.0以上机型,那就需要自定义通知了,因为android8.0以上的Notification引入了Channel的概念,声音是定义在Channel里面的,所以我们需要重写的 UmengMessageHandler 的 getNotification方法,给大家写了个例子参考:

public static final String SOUND_PATH = "android.resource://com.test.demo/raw/umeng_push_notification_default_sound";UmengMessageHandler messageHandler = new UmengMessageHandler() {@Overridepublic Notification getNotification(Context context, UMessage msg) {Uri soundUri = Uri.parse(SOUND_PATH);if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {NotificationChannel channel = new NotificationChannel("default", "Default_Channel", NotificationManager.IMPORTANCE_HIGH);channel.setSound(soundUri, Notification.AUDIO_ATTRIBUTES_DEFAULT);NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);if (notificationManager != null) {notificationManager.createNotificationChannel(channel);}}NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "default");RemoteViews myNotificationView = new RemoteViews(context.getPackageName(),R.layout.notification_view);myNotificationView.setTextViewText(R.id.notification_title, msg.title);myNotificationView.setTextViewText(R.id.notification_text, msg.text);myNotificationView.setImageViewBitmap(R.id.notification_large_icon,getLargeIcon(context, msg));myNotificationView.setImageViewResource(R.id.notification_small_icon,getSmallIconId(context, msg));builder.setContent(myNotificationView).setSmallIcon(getSmallIconId(context, msg)).setSound(soundUri).setTicker(msg.ticker).setAutoCancel(true);return builder.build();}};  

其中 notification_view 的自己写的通知的样式布局,给大家贴一下代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:background="#ffffff"android:layout_height="64dp"><RelativeLayoutandroid:id="@+id/upush_notification1"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_marginBottom="10dp"android:layout_marginTop="10dp"><ImageViewandroid:id="@+id/notification_large_icon"android:layout_width="48dp"android:layout_height="48dp"android:layout_marginLeft="10dp"android:src="@drawable/ic_launcher"android:scaleType="fitXY" /><TextViewandroid:id="@+id/notification_title"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:layout_marginTop="3dp"android:layout_toRightOf="@+id/notification_large_icon"android:maxLines="1"android:text="Title"android:textColor="#000000"android:textSize="16sp" /><TextViewandroid:id="@+id/notification_text"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_below="@+id/notification_title"android:layout_marginLeft="10dp"android:layout_marginTop="3dp"android:layout_toRightOf="@+id/notification_large_icon"android:ellipsize="marquee"android:focusable="true"android:focusableInTouchMode="true"android:marqueeRepeatLimit="marquee_forever"android:scrollHorizontally="false"android:fadingEdge="horizontal"android:singleLine="true"android:text="Message"android:textColor="#000000" /><requestFocus /></RelativeLayout><RelativeLayoutandroid:id="@+id/upush_notification2"android:layout_width="match_parent"android:layout_height="match_parent"android:visibility="gone"><ImageViewandroid:id="@+id/notification_small_icon"android:layout_width="match_parent"android:layout_height="match_parent"android:scaleType="fitXY" /></RelativeLayout>
</RelativeLayout>

写完自定义的Notification之后,通过友盟推送的 PushAgent set 一下就可以了:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {mPushAgent.setMessageHandler(messageHandler);}

打完收工,在友盟后台推送一条试一下就可以了

友盟推送自定义通知声音相关推荐

  1. java友盟自定义行为_实现友盟推送消息的完全自定义处理

    1,下面的前提是必须申请了友盟且有app key 3,若开发者需要实现对消息的完全自定义处理,则可以继承 UmengBaseIntentService, 实现自己的Service来完全控制达到消息的处 ...

  2. React Native集成友盟推送

    React Native集成友盟推送 android推送集成 1.导入SDK: (1)push文件夹位置: (2)将push文件夹直接复制粘贴到rn项目android目录下,目录结构如下: 2.添加修 ...

  3. 友盟推送8.0信息不展示(推送状态却为已送达)

    其实这种状况是由于android的版本过高,一开始的通知栏不能使用,需要在原本的通知栏上加一些设置,代码我已经放入service中 在appliaction 中的onCreat 方法中进行初始化友盟并 ...

  4. react-native 集成友盟推送

    react-native 集成友盟推送 公司开发app时用到了,友盟推送,但是友盟的官方文档写的比较模糊:粗略整理一下从集成友盟推送,到打开推送消息的处理过程:如有处理不合适的地方欢迎指正!!!! 集 ...

  5. android 友盟推送获取不到devicetoken,使用友盟消息推送中遇到的哪些问题--索引(开发者必读)...

    友盟推送服务器容量如何?每天耗电.耗流量多少?开发者自己的推送如何与友盟推送系统进行通讯?用户如何关闭推送服务?集成中有哪些坑?等等等等,汇总贴,供参考. 先来介绍下友盟推送有啥功能吧. 第一,支持多 ...

  6. java服务器端集成友盟,Android友盟推送集成

    第一次认真集成推送,碰到了一些问题,记录一下. 首先讲一下实现原理,我们用的是友盟.Android比iOS要麻烦很多. 友盟集成是需要后端配合的,具体就是后端调用友盟的接口,向友盟推送一条消息,然后友 ...

  7. Android集成友盟推送最详细介绍

    前言 如今大部分应用都会涉及到推送,正好最近的项目推送是我在搞,今天就分享一下我的使用过程. 集成方式 关于友盟推送的集成方式,文档已经介绍的很详细了,我就不在此多做解释. 友盟推送完整集成过程 完全 ...

  8. 友盟推送集成的常见问题

    友盟消息推送注意事项 SDK集成:http://dev.umeng.com/push/android/integration 常见问题:http://bbs.umeng.com/thread-5911 ...

  9. Android 友盟统计 友盟推送 友盟分享快速集成

    一.友盟统计 1.首先需要到友盟官网 http://mobile.umeng.com/apps注册并且添加新应用,获得Appkey 2.导入SDK,新版SDK支持Android 6.0,http:// ...

最新文章

  1. python是用什么语言开发的-专为人工智能和数据科学而生的Go语言,或将取代Python...
  2. go:系统参数or函数--未完
  3. 云服务器的协议,云服务器协议
  4. 一台电脑同时添加git和bitbucket两个网站的ssh key
  5. Shiro教程_2 Shiro+SpringBoot+Mysql+Redis(缓存)
  6. DEM数据下载、镶嵌等问题
  7. 第一次申请去美国面签,需要注意哪些事项提高成功率?
  8. 用ANSYS画矩形_ANSYS软件使用的几点建议
  9. windows只能单向ping通
  10. 【云驻共创】初探数通网络开放可编程
  11. 最新昆石VOS2009/VOS3000手机号段导入文件(手机归属地)
  12. django传值给模板, 再用JS接收并进行操作
  13. 史上最BT的真实案例集
  14. EasyX接收并显示从控制台输入的数字和英文
  15. php使用ZipArchive扩展实现文件的zip压缩与zip解压
  16. 2018 北京化工大学ACCA精英班招生简章
  17. 软件流程和管理(九):外包,合同和采购
  18. 安装 slowhttptest ddos攻击软件
  19. DevExpress Winform LabelControl 文本竖向纵向显示
  20. 初学CAD制图时,不同制图工具的技巧分析

热门文章

  1. python程序设计实验指导书_《Python程序设计》实验指导书.pdf
  2. Early bird 捷足先登
  3. 当你还在犹豫不决的时候,其他小伙伴已经捷足先登了!
  4. Android多线程和异步任务
  5. 青岛啤酒与德国啤酒:纯爽背后的渊源与秘密
  6. 导航电子地图制作资质的办理指南
  7. VSCode + JSDoc 完美实现(almost)JavaScript代码提示
  8. Linux下C语言Socket编程
  9. Flash 安装失败
  10. java 304_304 Not Modified状态码