在特定日期和时间设置静音模式
我想在将来发生特定事件时将铃声模式设置为静音。仅当选中首选项中的复选框时才会发生这种情况。我知道我必须更新权限清单,并且我可以使用如下方式设置铃声模式:
if (getPreferences(MODE_PRIVATE).getBoolean(PREFS_KEY_SILENTOPTION, false)) {
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}
但是如何在将来的一段时间内设置(和重置)它?
I'd like to set the ringer mode to silent for specific events in the future. It should only happen if a checkbox in the preferences is checked. I know that I have to update the manifest for the permissions and also that I can set the ringer mode with something like this:
if (getPreferences(MODE_PRIVATE).getBoolean(PREFS_KEY_SILENTOPTION, false)) {
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}
But how can I set (and reset) it for a space of time in the future?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 AlarmManager。它允许您“安排您的应用程序在将来的某个时间运行”。
Check out the AlarmManager. It allows you to "schedule your application to be run at some point in the future".