4

如何为我的 android 应用程序设置通知声音。在我的应用程序中,通知将在 30 秒后显示。我想为此警报提供选项,例如静音模式、振动模式以及从设备的可用音调中进行选择的选项。我正在使用首选项屏幕来显示设置菜单。我想设置特定的通知铃声类型应用程序。有什么办法可以建立这个..

4

2 回答 2

11

如何为 Android 通知设置自定义声音

将 .mp3 或 .wav 文件放在 res/raw 目录中,例如“notification_sound.mp3”,如下例所示(文件名不得使用大写字母)。

在创建通知时设置 Notification.sound,如下所示:

final int iconResId = R.drawable.my_icon;
final int soundResId = R.raw.notification_sound;
final Notification notification =
    new Notification(iconResId, tickerText, System.currentTimeMillis());
final String packageName = context.getPackageName();
notification.sound =
    Uri.parse("android.resource://" + packageName + "/" + soundResId);

或者,为您的通知添加振动:

notification.defaults = Notification.DEFAULT_VIBRATE;
于 2013-03-07T09:20:10.773 回答
2

http://developer.android.com/reference/android/app/Notification.Builder.html#setSound(android.net.Uri )

Notification.Builder.setSound();

在偏好活动中使用铃声偏好来获取所选声音的 URI。

于 2011-02-28T15:07:45.873 回答