Java 类android.app.AlarmManager.AlarmClockInfo 实例源码

项目:BipolAlarm    文件:AlarmUtils.java   
public static AlarmClockInfo setAlarm(Context con, int hour, int min) {
    Calendar now = Calendar.getInstance();
    Calendar alarm = Calendar.getInstance();
    alarm.set(Calendar.HOUR_OF_DAY, hour);
    alarm.set(Calendar.MINUTE, min);
    alarm.set(Calendar.SECOND, 0);
    if (alarm.before(now)) alarm.add(Calendar.HOUR_OF_DAY, 24);  // alarm should ring in future
    String alarmDateText = DateFormat.getDateTimeInstance().format(alarm.getTime());
    Log.v(LOGGING_TAG, "Alarm time set to " + alarmDateText);

    long triggerTime = alarm.getTimeInMillis();
    AlarmClockInfo acInfo = setAlarm(con, triggerTime);

    Toast.makeText(con, con.getString(R.string.toast_alarm_set), Toast.LENGTH_LONG).show();
    return acInfo;
}
项目:Asynchronous-Android-Programming    文件:AlarmClockActivity.java   
@Override
public void onClick(View v) {

    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, 1);
    calendar.set(Calendar.HOUR_OF_DAY, 22);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);

    Intent intent = new Intent("my_alarm");
    intent.putExtra("exactTime", calendar.getTimeInMillis());
    PendingIntent broadcast = PendingIntent.getBroadcast(
            AlarmClockActivity.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);

    if (Build.VERSION.SDK_INT >= 23) {

        AlarmClockInfo alarmInfo = new AlarmClockInfo(
                calendar.getTimeInMillis(),
                // Create
                createShowDetailsPI());
        am.setAlarmClock(alarmInfo, broadcast);
    } else {

        am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), broadcast);
    }
}
项目:BipolAlarm    文件:AlarmUtils.java   
public static AlarmClockInfo setAlarm(Context con, long triggerTime) {
    if (triggerTime < System.currentTimeMillis()) return null;
    AlarmClockInfo acInfo = new AlarmClockInfo(triggerTime, getShowIntent(con));
    alarmManager(con).setAlarmClock(acInfo, getAlarmIntent(con));
    updateAlarmInfo(con, true, triggerTime);
    return acInfo;
}
项目:BipolAlarm    文件:AlarmUtils.java   
public static AlarmClockInfo setRingAlarm(Context con, int relMin) {
    long triggerTime = System.currentTimeMillis() + 60000*relMin;
    AlarmClockInfo acInfo = new AlarmClockInfo(triggerTime, getShowIntent(con));
    alarmManager(con).setAlarmClock(acInfo, getRingIntent(con));
    updateAlarmInfo(con, true, triggerTime);
    return acInfo;
}