고정 된 날짜와 시간에 나에게 알람을 줄 안드로이드 앱을 만들고 싶습니다. 날짜에 대해 나는 텍스트 필드에서 시간을 가져 가기 위해 날짜 선택 도구와 시간 선택 도구를 사용했습니다. 다음과 같이 밀리 초 단위로 날짜와 시간을 병합했습니다.안드로이드의 고정 날짜와 시간에 알람 관리자
public void mergedt(){
String myDate = textDate.getText().toString();
String myTime = textTime.getText().toString();
String toParse = myDate + " " + myTime;
// viewtext.setText(toParse + " ");
try {
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm");
Date date = formatter.parse(toParse);
millis = date.getTime();
viewtext.setText(millis + "");
//viewtext.setText(date + "");
} catch (ParseException pe) {
pe.printStackTrace();
}
}
내가 알람을 설정하려면
long milliseconds = new GregorianCalendar().getTimeInMillis();
에 따라 현재 날짜와 시간 (밀리 초)을 변환 한, 나는 코드 나는 알람을 설정
public void setAlarm(View view){
long interval = millis - milliseconds;
long time = new GregorianCalendar().getTimeInMillis() + interval;
Intent intent = new Intent(this,AlarmReceiver.class);
AlarmManager alarm_Manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarm_Manager.set(AlarmManager.RTC_WAKEUP,time, PendingIntent.getBroadcast(this, 1,intent, PendingIntent.FLAG_UPDATE_CURRENT));
}
다음 사용하고, 그것은 보여줍니다 "경고"메시지는 즉시 고정 날짜와 시간에 알람을 표시하지 않습니다. 코드에 어떤 문제가 있으며 어떻게 해결할 수 있습니까?
는 사용자가 입력 한 날짜가 현재 날짜 이후 당신의 확신? –
네, 맞습니다. – rabiul