public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 통지 매니저를 취득
setmNotification((NotificationManager) getSystemService(NOTIFICATION_SERVICE));
// 알람 매니저를 취득
mManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
// 현재 시각을 취득
mCalendar = new GregorianCalendar();
Log.i("HelloAlarmActivity", mCalendar.getTime().toString());
// 셋 버튼, 리셋버튼의 리스너를 등록
setContentView(R.layout.activity_main);
Button b = (Button) findViewById(R.id.set);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(getApplicationContext(), " 설정완료 >.< ", Toast.LENGTH_SHORT).show();
setAlarm();
}
});
b = (Button) findViewById(R.id.reset);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
resetAlarm();
}
});
start_music = MediaPlayer.create(getBaseContext(), R.raw.abc);
// 일시 설정 클래스로 현재 시각을 설정
mDate = (DatePicker) findViewById(R.id.date_picker);
mDate.init(mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH),
mCalendar.get(Calendar.DAY_OF_MONTH), this);
mTime = (TimePicker) findViewById(R.id.time_picker);
mTime.setCurrentHour(mCalendar.get(Calendar.HOUR_OF_DAY));
mTime.setCurrentMinute(mCalendar.get(Calendar.MINUTE));
mTime.setOnTimeChangedListener(this);
}
// 알람의 설정
private void setAlarm() {
mManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, mCalendar.getTimeInMillis(),
pendingIntent());
Log.i("HelloAlarmActivity", mCalendar.getTime().toString());
}
// 알람의 해제
private void resetAlarm() {
mManager.cancel(pendingIntent());
start_music.stop();
}
// 알람의 설정 시각에 발생하는 인텐트 작성
private PendingIntent pendingIntent() {
Toast.makeText(getApplicationContext(), " 알람시간 >.< ", Toast.LENGTH_SHORT).show();
start_music.start();
return null;
}
// 일자 설정 클래스의 상태변화 리스너
public void onDateChanged(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
mCalendar.set(year, monthOfYear, dayOfMonth, mTime.getCurrentHour(),
mTime.getCurrentMinute());
Log.i("HelloAlarmActivity", mCalendar.getTime().toString());
}
// 시각 설정 클래스의 상태변화 리스너
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
mCalendar.set(mDate.getYear(), mDate.getMonth(), mDate.getDayOfMonth(),
hourOfDay, minute);
Log.i("HelloAlarmActivity", mCalendar.getTime().toString());
}
public NotificationManager getmNotification() {
return mNotification;
}
public void setmNotification(NotificationManager mNotification) {
this.mNotification = mNotification;
}
}
set버튼을 눌러 시간을 설정하게 되면 설정된시간에 음악이나오는게 아니라 set버튼을 눌르자마자 노래가나옵니다. 어떤 문제점이 있는건가여 ???