2013-05-26 17 views
0

我发出了一个声音通知,当它通知发出声音但从未停止。有什么办法限制通知的声音时间吗?通知声音变得无穷无尽并且永不止步

这是我的通知代码

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
      context).setSmallIcon(R.drawable.icon) 
      .setContentTitle(title).setContentText(detail); 

mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); 
mBuilder.setDefaults(Notification.DEFAULT_LIGHTS); 


SharedPreferences pref = PreferenceManager 
    .getDefaultSharedPreferences(context); 

String sound = pref.getString("ringtonePref", "default"); 
Uri uri = Uri.parse(sound); 
mBuilder.setSound(uri,RingtoneManager.TYPE_ALARM); 
+0

notification.flags | = Notification.FLAG_AUTO_CANCEL; \t notification.defaults | = Notification.DEFAULT_SOUND; –

回答

0

一些铃声包含ANDROID_LOOP元数据,使音乐循环。 这些声音将永远循环播放。因此,最好使用特定于默认通知的声音或没有ANDROID_LOOP元数据的声音。

1

我相信你需要将TYPE_ALARM更改为TYPE_NOTIFICATION

+0

它是TYPE_NOTIFICATION,但没有奏效。 – BlaShadow

4

有同样的问题。我使用NotificationBuilder来构建一切。调用build()来获取noti对象,我做了以下操作:

notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
notification.audioStreamType = AudioManager.STREAM_NOTIFICATION; 
+0

这帮了我很多!感谢分享伴侣! –