自定义通知声音无法播放

时间:2014-06-05 23:45:34

标签: android android-notifications

我正在使用默认通知声音和振动 builder.setDefaults(RingtoneManager.TYPE_NOTIFICATION) 这很完美。 但是我决定允许用户使用首选项选择通知。

这适用于检索用户选择,但使用此代码不会播放声音(无论选择如何)。我知道声音文件存在,因为它们随手机一起提供。

public void sendNotification(Context context, String sender, long millis)
{
    int num = DATABASE_HELPER.countUnread();
    Log.i("Notification sound", SETTINGS.notification().toString());
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.notification_icon)
            .setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS)
            .setSound(SETTINGS.notification())
            //.setAutoCancel(true)
            .setContentTitle(sender)
            .setContentText("New Message" + (num > 1 ? "s" : ""))
            .setWhen(millis)
            .setNumber(num);
    builder.setContentIntent(getNotificationIntent(context));
    NotificationManager manager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    manager.notify(NOTIFICATION_ID, builder.build());
}

这会在日志中产生输出content://media/internal/audio/media/18,手机振动(尽管它是一种不同的模式,可能是RingtoneManagerNotification默认值之间的差异),但没有声音是播放。

在人们问之前,是的,我确实检查了音量/手机没有静音等。

0 个答案:

没有答案
相关问题