android cannot get sound to play from a notification
I have the following code to produce a notification. The notification comes up but no sound. I have the following code to pouyt the sound on
notification.defaults |= Notification.DEFAULT_SOUND;
code listing
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.setL开发者_高级运维atestEventInfo(gContext, "Your teeth appoitmernt:", "Date:", contentIntent);
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_LIGHTS;
manager.notify(1,notification);
cDates.SetAlarm(i);
Ted
You should try setting
notification.defaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS;
or setting explicitly:
notification.sound =
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Not sure if you resolved this but I had the same problem and it's because you have
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_LIGHTS;
but you need to assign it first like
notification.defaults = Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_LIGHTS;
or more simply as @rekaszeru put
notification.defaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS;
精彩评论