android无法通过通知播放声音

时间:2011-05-03 11:04:19

标签: android audio notifications

我有以下代码来生成通知。通知出现但没有声音。我有以下代码来播放

上的声音
notification.defaults |= Notification.DEFAULT_SOUND;

代码列表

    NotificationManager manager = (NotificationManager)     gContext.getSystemService(Context.NOTIFICATION_SERVICE);

    Notification notification = new Notification(R.drawable.icon, "Teeth Alert", System.currentTimeMillis());
    PendingIntent contentIntent = PendingIntent.getActivity(gContext, 0, new Intent(gContext, NotifyMessage.class), 0);
    notification.setLatestEventInfo(gContext, "Your teeth appoitmernt:", "Date:", contentIntent);

    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_LIGHTS;

    manager.notify(1,notification);
    cDates.SetAlarm(i);

泰德

2 个答案:

答案 0 :(得分:11)

你应该尝试设置

notification.defaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS;

或明确设置:

notification.sound = 
    RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

答案 1 :(得分:1)

不确定你是否解决了这个问题,但我遇到了同样的问题,因为你有

notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_LIGHTS;

但您需要先将其指定为

notification.defaults = Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_LIGHTS;

或更简单地说@rekaszeru把

notification.defaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS;