public class Settime extends Activity implements OnClickListener {
String address;// 定义变量address,存储socket通信连接的ip地址
int nport;// 定义变量nport,存储socket通信连接的端口号
int which;
SharedPreferences pre_set;
int progress_set;
SharedPreferences.Editor edito
Calendar c = Calendar.getInstance();
AlarmManager aManager1;
//***************以上是下面要用到的变量的创建*********************************
//*****************************我利用timepicker来获取要设定的时间
timepicker.setOnTimeChangedListener(new OnTimeChangedListener() {
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub
String hour, minutes = null, message;
c.setTimeInMillis(System.currentTimeMillis());
c.set(Calendar.HOUR_OF_DAY, hourOfDay);
c.set(Calendar.MINUTE, minute);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
}
});这是通过timepicker来确定闹钟时间。
//*******************************************这是点击设定按钮触发的事件************************************
case R.id.button_set: {
Intent intent = new Intent(Settime.this, MyReceiver.class);
intent.putExtra("address", address);
intent.putExtra("nport", nport);
intent.putExtra("用户设定的窗帘状态", progress_set);
intent.putExtra("progress", Chuanglian.lastProgress);
intent.putExtra("控制周的循环", array);
PendingIntent pi = null;
switch (which) {
//这个which是判断哪个按钮点击而启动该activity.对应的,case1,第一个按钮点击之后设置的闹钟。case2,第二个按钮点击之后设置的闹钟。以此类推
case 1:
pi = PendingIntent.getBroadcast(Settime.this,1,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
break;
case 2:
pi = PendingIntent.getBroadcast(Settime.this,2,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
break;
case 3:
pi = PendingIntent.getBroadcast(Settime.this,3,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
break;
case 4:
pi = PendingIntent.getBroadcast(Settime.this,4,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
break;
case 5:
pi = PendingIntent.getBroadcast(Settime.this,5,
intent, PendingIntent.FLAG_UPDATE_aaaCURRENT);
break;
case 6:
pi = PendingIntent.getBroadcast(Settime.this,6,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
break;
}
// 设置AlarmManager将在对应的时间启动
// 如果设定的时间早于当前时间,则往后移一天。
long time = c.getTimeInMillis();
System.out.println(which);
Calendar nowTime = Calendar.getInstance();
long time1 = nowTime.getTimeInMillis();// 当前时间
if (time < time1)
time += 3600 * 24 * 1000;
aManager1.setRepeating(AlarmManager.RTC_WAKEUP, time,
3600 * 1000 * 24, pi);