Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android通知播放默认声音而不是自定义声音_Android_Notifications - Fatal编程技术网

Android通知播放默认声音而不是自定义声音

Android通知播放默认声音而不是自定义声音,android,notifications,Android,Notifications,我正在尝试使用Android的通知管理器,即,Android.app.Notification和Android.app.NotificationManager,在我的Android设备上使用以下代码,该设备具有操作系统4.4.2,运行非常好。 在一些较旧的操作系统(如4.2.x)上,它们似乎不能正常工作。我看到一个通知弹出,但声音是默认的通知声音,而不是我选择的声音,这在我的设备4.4.2上运行良好 Uri alarmSound = Uri.parse("/storage/sdcard1/MyA

我正在尝试使用Android的通知管理器,即,Android.app.NotificationAndroid.app.NotificationManager,在我的Android设备上使用以下代码,该设备具有操作系统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()获取的,并且文件位于指定位置。由于这在我的设备上运行得很好,而在旧设备上运行得不好,所以首先想到的问题是操作系统版本,但我找不到旧版本的解决方案

更新 因此,这似乎不是操作系统的问题,因为我在另一台安卓设备上用OS4.2.2对它进行了测试,它运行正常

仍然无法找出原因

notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.pop);
将声音文件添加到原始文件夹中


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

问题是我不能这样做,因为我的应用程序具有下载所需警报声音并在应用程序中使用的功能。问题是我不能这样做,因为我的应用程序具有下载所需警报声音并在应用程序中使用的功能。