本文介绍了Android的通知,只播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个倒数计时器在我的活动,当它达到零我发送通知到状态栏也扮演一个自定义的wav文件,以提醒用户。我只是想,如果用户不使用的时候应用程序显示在状态栏的通知,但我还是想为wav文件播放计时器应用程序是否可见或不可见。

是否有可能使Android的通知仅播放音频警报?我一直使用 中的MediaPlayer播放的wav文件,而不是尝试,但这种使用其自己的音量设置,不是正规通知音量,所以如果你的媒体音量低则通知,播放声音在低量太大,我不想要的。我想要的声音在同一体积的其他通知播放。

我使用的是这样的:http://developer.android.com/guide/topics/ui/notifiers/notifications.html

和供给的声音是这样的:

  notification.sound = Uri.parse(android.resource://+ getPackageName()+/+ R.raw.notifysnd);
 

解决方案

在添加声音部分中http://developer.android.com/guide/topics/ui/notifiers/notifications.html有这样一个字条:

所以,如果你想定制唯一的声音,你可以使用 -

  notification.sound = Uri.parse(android.resource://+ getPackageName()+/+ R.raw.notifysnd);
notification.defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE;
 

I have a countdown timer in my activity and when it reaches zero I send a notification to the status bar which also plays a custom wav file to alert the user. I only want the status bar notification to appear if the user isn't using the app at the time but I still want the wav file to play whether the timer app is visible or not.

Is it possible to make the Android notification only play the audio alert? I've tried using MediaPlayer to play the wav file instead but this uses its own volume settings and not the regular notification volume so if your media volume is low then the notification sound plays at a low volume too which I don't want. I want the sound to play at the same volume as other notifications.

I'm using this:http://developer.android.com/guide/topics/ui/notifiers/notifications.html

And supplying the sound like this:

notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notifysnd);
解决方案

In 'Adding a sound' section in http://developer.android.com/guide/topics/ui/notifiers/notifications.htmlthere is this note :

So, if you want to customize only sound, you may use -

notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notifysnd);
notification.defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE;

这篇关于Android的通知,只播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 10:12
查看更多