【问题标题】:Android Notification plays default sound instead of CustomAndroid Notification 播放默认声音而不是 Custom
【发布时间】:2016-09-23 20:40:12
【问题描述】:

我正在尝试使用 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() 获得的,并且文件存在于指定位置。由于这在我的设备上运行良好,而不是在旧设备上,所以首先想到的是操作系统版本的问题,但我找不到旧版本的解决方案。

更新 所以这似乎不是操作系统的问题,因为我在另一台使用 OS 4.2.2 的 Android 设备上对其进行了测试并且它工作正常。

还是查不出原因……

【问题讨论】:

    标签: android notifications


    【解决方案1】:
    notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.pop);
    

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

    【讨论】:

    • 问题是我不能这样做,因为我的应用程序具有下载所需警报声音并在应用程序中使用的功能。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-07
    • 2017-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多