android - 覆盖通知声音Android

标签 android audio notifications

我试图覆盖通知声音并播放自己的通知声音。
当前代码是:

NotificationCompat.Builder mBuilder =
    new NotificationCompat.Builder(context)
    .setSmallIcon(R.drawable.ic_notifications_white_24dp)
    .setContentTitle(text)
    .setColor(context.getResources().getColor(R.color.colorAccent))
    .setSound(soundUri);
// Sets an ID for the notification
int mNotificationId = 2580;

// Gets an instance of the NotificationManager service
NotificationManager mNotifyMgr =
    (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// Builds the notification and issues it.
mNotifyMgr.notify(mNotificationId, mBuilder.build());

但是原始通知(通过声音)覆盖了我的声音。
有什么办法吗?

编辑:

当我尝试播放声音时,两个声音都在播放。有时原始声音优先,而自定义声音则首先播放。

我只想听到自定义声音。

最佳答案

创建res/raw文件夹并将通知声音放入此文件夹

试试这个

notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notifysound);

关于android - 覆盖通知声音Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38543299/

相关文章:

android - 安全取消后台线程中的 ORMLite 写入

Android 删除进度对话框焦点并使其下的 gridview 可聚焦?

actionscript-3 - 播放库中的声音几乎不会引起延迟ActionScript 3.0

java - 非 Activity 类的Android通知

Android:ScrollView 不适用于 TableLayout

java - RxJava 2 : BehaviorSubject and Observable. 合并最新问题

android - Android 混音是如何工作的?

flash - 如何反转音量 slider 的音量数学?

android - 即使在应用程序终止后也能收到 Mqtt 通知

ios - 如何使用 Xamarin iOS 发送具有不同类别标识符的多个通知?