Android 通知播放 Assets 文件夹中的声音

标签 android android-notifications android-resources android-assets

我正在尝试播放 Assets 文件夹中的通知声音,但是当通知触发时,会显示通知但没有播放声音,并且 logCat 中没有错误或警告。我正在使用此代码创建通知:

builder = new NotificationCompat.Builder(context)
                    // Set Icon
                    .setSmallIcon(R.drawable.ic_launcher)
                    // Set Ticker Message
                    .setTicker(message)
                    // Set Title
                    .setContentTitle(message)
                    // Set Text
                    .setContentText(context.getString(R.string.app_name))
                    // Add an Action Button below Notification
                    .addAction(R.drawable.share,
                            context.getString(R.string.share), pendingShare)
                    // Set PendingIntent into Notification
                    .setContentIntent(contentIntent)
                    // Dismiss Notification
                    .setAutoCancel(true)
                    .setSound(
                            Uri.parse("file:///android_assets/"
                                    + prefs.getString(Constants.NOTIF_SOUND,
                                            "mp3/al_affassi_full.mp3")));

有人可以帮我解决这个问题吗? 谢谢!

最佳答案

将您的 mp3 文件放在 raw 文件夹下。如果你把它放在 asset/ 下,它会被压缩两次,你不能使用它。

关于Android 通知播放 Assets 文件夹中的声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27581570/

相关文章:

java - AppCompat 如何扩展未明确使用 AppCompat 小部件的布局?

android - 如何通过 IP 连接计算视频的丢包率、抖动和 QoS 参数?

android - 图书馆项目和资源

android - Resources$NotFoundException 用于 Vivo 设备上的少数 Drawable

Android ImageView 根据标签设置图片

android - 如何为我的 Android 应用程序设置 session 超时

android - 从工具栏 AppCompat 的 SearchView 中删除后退按钮

Android:有没有办法禁用通知 bundle ?

android - 来自前台服务的 Nav Deep Link

android - 如何从应用程序内部关闭应用程序通知