Android 事件:响铃、振动并显示警报框
我正在尝试在 Android 中创建一个事件,当到达 schedules 事件的时间时,我想显示一个警报框,让手机响铃和振动。有人可以帮忙吗? 谢谢
I am trying to create an event in Android and when the time of the scedules event is reach, I want to display an alert box, ring and vibrate the phone. Can someone please help on this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 Handler 类文档
更多信息可以在此处找到。在您的情况下,您似乎需要
postAtTime
或postDelayed
。代码看起来像这样From the Handler class documentation
More information can be found here. In your case it seems that you need either
postAtTime
orpostDelayed
. The code would look something like您需要使用 AlarmManager 设置警报。
然后,您需要一个广播接收器来在时间到时执行您的任务。
要响铃,您需要使用您喜欢的声音(通知/铃声/警报)的 URI 来使用 MediaPlayer,要振动,您将使用振动器服务:
振动器 v = (振动器) getSystemService(Context.VIBRATOR_SERVICE);
现在您已经有了大概的了解,我建议您阅读一些示例和 Android 网站以了解更多详细信息...
You will need to set an alarm using the AlarmManager.
Then you need a BroadcastReceiver to perform your tasks when the time is up.
To ring you would need to use the MediaPlayer using the URI of your preferred sound (notification / ringtone / alarm) and to vibrate you will be using the Vibrator service:
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
Now that you have the general idea I suggest you read some examples and the Android website for more details...