简体   繁体   English

如何在Android中触发闹钟,即播放闹钟铃声?

[英]How can I set off an alarm i.e. play an alarm tone in Android?

I want to build an alarm application but I don't know how to set off an alarm ringtone when the alarm has gone off. 我想构建一个警报应用程序,但是我不知道在警报响起后如何设置警报铃声。 How do I do this? 我该怎么做呢?

Since youre Question is pretty broad and generic, I cant provide exact Code but i can point you to the things you need to do. 由于您的问题相当广泛且笼统,因此我无法提供确切的代码,但我可以指出您需要做的事情。

You need to create a PendingIntent which starts a Service . 您需要创建一个PendingIntent来启动Service In the Service you need to play the Sound with a MediaPlayer . 在服务中,您需要使用MediaPlayer播放声音。 The Media Playback Link also has a specific section on playing Sound in a Service. 媒体播放链接还包含有关播放服务中声音的特定部分。 To schedule the PendingIntent to be fired at a certain time and start the service then, use AlarmManager . 要计划在某个时间触发PendingIntent并启动服务,请使用AlarmManager

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM