【发布时间】:2014-09-01 22:40:05
【问题描述】:
我已经查看了有关此主题的几个问题,并且似乎都建议在通知生成器中简单地使用.setSound(alarmSound) 会导致手机在通知中播放声音。但是,我正在这样做,但它不起作用。
我可能遗漏了一些东西,但我找不到它是什么。
这是我用来发出通知的代码:
private void newArrivalNotification(String locId, String userId) {
...
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
Intent mainActivity = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, locId.hashCode(),
mainActivity, 0);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
if(alarmSound == null) {
Log.w("GcmIntentService", "alarmSound is null");
}
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(title)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setSound(alarmSound, AudioManager.STREAM_NOTIFICATION)
.setTicker(msg)
.setContentText(msg);
mBuilder.setContentIntent(contentIntent);
Notification arrivalNotification = mBuilder.build();
arrivalNotification.defaults |= Notification.DEFAULT_VIBRATE;
mNotificationManager.notify(NOTIFICATION_ID, arrivalNotification);
}
你能发现我做错了什么吗?我找了几个小时也没找到。
【问题讨论】:
标签: android audio notifications