Android Notification播放默认声音而非自定义

时间:2016-09-23 11:09:32

标签: android notifications

我正在尝试使用Android的通知管理器,即 android.app.Notification android.app.NotificationManager ,使用以下代码完美地运行我的Android设备有OS 4.4.2。 似乎他们在一些较老的操作系统上说不能正常工作,如4.2.x.我看到一个通知弹出,但声音是默认通知声音,而不是我选择的声音,这在我的设备上工作正常,这是4.4.2。

Uri alarmSound = Uri.parse("/storage/sdcard1/MyApp/Media/Sounds/fire.mp3");

NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
            inboxStyle.setBigContentTitle(notificationString);

PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                    (new Intent(context, NavigationMenu.class)),
                    0);

Notification notification = new NotificationCompat.Builder(context)
                            .setSmallIcon(R.drawable.logo_black)
                            .setContentTitle(notificationString)
                            .setContentText(notificationString)
                            .setContentIntent(pendingIntent)
                            .setAutoCancel(true)
                            .setSound(alarmSound)
                            .build();

mNotificationManager.notify(notificationId, notification);

uri实际上不是硬编码的,而是使用 Environment.getExternalStorageDirectory()获得的,并且该文件存在于指定位置。由于这在我的设备上完全正常工作而不是在旧设备上工作,首先想到的是OS版本的问题,但我找不到旧版本的解决方案。

更新 所以这似乎不是操作系统的问题,因为我在另一台运行OS 4.2.2的Android设备上测试它并且它有效。

还是无法挖掘原因...

1 个答案:

答案 0 :(得分:0)

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

将声音文件添加到原始文件夹中。

相关问题