简体   繁体   English

如何使用RTC唤醒和警报意图

[英]How to use RTC Wake Up and alarm Intent

I'm working on a project, my goal is to configurate a cell phone. 我正在做一个项目,我的目标是配置手机。 I have to related the sounds of the phone with a calendar . 我得把电话的声音和日历联系起来

The user can choose the day, the beginning hour and the ending hour and, the configuration parameters of the sound. 用户可以选择日期,开始时间和结束时间,以及声音的配置参数。 An example, every monday, the application has to put the phone in silence mode, between 8 am and 4 pm . 例如,每个星期一,应用程序必须在上午8点至下午4点之间将电话置于静音模式

I already have all the parameters, all I have to do now, is to apply them. 我已经拥有了所有参数,现在我要做的就是应用它们。 To do so, I think the use of RTC Wake Up is the best. 为此,我认为最好使用RTC Wake Up

Here's the code that i'm working on : 是我正在处理代码

TimePicker hourBeginning = (TimePicker)findViewById(R.id.hourBeginningTimePicker);
TimePicker hourEnding = (TimePicker)findViewById(R.id.hourEndingTimePicker);
SeekBar volumePhone = (SeekBar)findViewById(R.id.volumePhoneOptionSeekBar);
SeekBar volumeAlarm = (SeekBar)findViewById(R.id.volumeAlarmOptionSeekBar);
SeekBar volumeApplication = (SeekBar)findViewById(R.id.volumeApplicationOptionSeekBar);

Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, heureBeginning.getCurrentHour());
calendar.set(Calendar.MINUTE, heureEnding.getCurrentMinute());


// With setInexactRepeating(), you have to use one of the AlarmManager interval
// constants--in this case, AlarmManager.INTERVAL_DAY.
alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
                AlarmManager.INTERVAL_DAY, alarmIntent);

I don't understand how this works, and how it suppose to solve my problem : 我不知道这是如何工作的,以及它应该如何解决我的问题

// With setInexactRepeating(), you have to use one of the AlarmManager interval
// constants--in this case, AlarmManager.INTERVAL_DAY.
alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
                AlarmManager.INTERVAL_DAY, alarmIntent);

If you think, there's a better solution, or know how to use correctly RTC Wake Up to solve my problem, help would be appreciated. 如果您认为有更好的解决方案,或者知道如何正确使用RTC Wake Up解决我的问题,将不胜感激。

Thanks. 谢谢。

Use alarm manager to trigger the alarm at a specific defined time. 使用警报管理器在特定的定义时间触发警报。

AlarmManager alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(getApplicationContext(),
            xyz.class);

    PendingIntent alarmIntent = PendingIntent
            .getService(getApplicationContext(), 0, intent,
                    PendingIntent.FLAG_ONE_SHOT);

    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 14);
    calendar.set(Calendar.MINUTE, 00);
    calendar.set(Calendar.SECOND, 00);

    alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP,
            calendar.getTimeInMillis(), 1000 * 60 * 60 * 24, alarmIntent);

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

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