Android:寻找一种简单的方法来手动循环播放通知声音
我正在摆弄一个弹出并显示警报信息的对话框。 (我知道,据记录,在 Android 中,使用通知是“更好”的风格,但就像闹钟一样,我希望它在您所做的任何事情之上显示一个对话框,以真正引起用户立即注意 - 作为用户期望这种行为,我不认为这是不好的风格!)
现在 - 我发现的唯一简单的方法是使用 RingtoneManager.getRingtone()
函数来获取 Ringtone
对象对于“警报”类型。
好吧,我现在可以使用 Ringtone.play()
播放该声音 - 但它只播放一次声音,我不知道如何让它无休止地播放,直到用户做出反应,例如通过触摸对话框任何地方或使用提供的“取消”按钮将其关闭。
有谁知道如何轻松实现这一点? 谢谢!
I am fiddling around with a dialog that pops up and displays an alarm information. (I know, it has been documented that in Android it's "better" style to use notifications instead, but just like the alarm clock I want it to display a dialog on top of whatever you do to really get the users immediate attention - as the user expects this behavior I don't think it's bad style!)
Now - the only easy way I found is using the RingtoneManager.getRingtone()
function to get a Ringtone
object for the type "alarm".
Well, I can play that sound now using Ringtone.play()
- but it plays the sound only once and I cannot figure out how to let it play endlessly until the user reacts, e.g. by touching the dialog anywhere or dismissing it using Cancel button provided.
Does anyone know how this can be accomplished easily?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看一下
AlarmClock
来自 Android 的 git 存储库。查看有关如何在预期持续时间内播放声音的源代码可能会有所帮助。Take a look at
AlarmClock
from Android's git repository. It might be helpful to check out the source code on how to play sounds for an expected duration.