2012-07-31 2 views
0

안녕하세요 저는 푸시를 통해 알람을 생성하므로 알림을 받으면 알람을 설정합니다. 모든 것은 잘 작동하지만, 순간 내가 푸시를하는 순간에 알람이 표시됩니다. 내가 말한 순간이 아닙니다. 여기 Android - 알람 문제 설정

내 코드입니다 :

public void set_alarm(int year, int month, int day, int hour, int minute, 
     String title) { 

    Calendar cal = Calendar.getInstance(); 
    cal.set(Calendar.MONTH, 5); 
    cal.set(Calendar.YEAR, 2012); 
    cal.set(Calendar.DAY_OF_MONTH, 31); 
    cal.set(Calendar.HOUR_OF_DAY, 9); 
    cal.set(Calendar.MINUTE, 46); 

    Intent intent = new Intent(c, AlarmActivity.class); 
    intent.putExtra("title", title); 
    PendingIntent pendingIntent = PendingIntent.getBroadcast(
      c.getApplicationContext(), 1253, intent, 
      PendingIntent.FLAG_UPDATE_CURRENT | Intent.FILL_IN_DATA); 

    AlarmManager alarmManager = (AlarmManager) c 
      .getSystemService(c.ALARM_SERVICE); 

    alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 
      pendingIntent); 
} 

그리고 여기에 통지받는 클래스입니다 :

public class AlarmActivity extends BroadcastReceiver { 

@Override 
public void onReceive(Context c, Intent i) { 
    Toast.makeText(c, "Alarm worked.", Toast.LENGTH_LONG).show(); 

    int icon = R.drawable.ic_dialog_alert; 
    long when = System.currentTimeMillis(); 

    Bundle bundle = i.getExtras(); 
    String title = bundle.getString("title"); 

    final int NOTIF_ID = 1234; 
    NotificationManager notofManager = (NotificationManager) c 
      .getSystemService(Context.NOTIFICATION_SERVICE); 

    Intent notificationIntent = new Intent(c, AnonymeActivity.class); 
    PendingIntent contentIntent = PendingIntent.getActivity(c, 0, 
      notificationIntent, 0); 
    Notification notification = new Notification(icon, "Faraway", when); 

    notification.setLatestEventInfo(c, "Faraway alarm", title, 
      contentIntent); 

    notification.flags = Notification.FLAG_INSISTENT; 
    notification.defaults |= Notification.DEFAULT_SOUND; 

    notofManager.notify(NOTIF_ID, notification); 
} 

}

감사

답변

1

당신은에 일정 인스턴스를 만들을 날짜 : 2012 년 5 월 31 일, 현재 날짜 이전입니다. 해당 문서에 따르면

:

시간이 과거에 발생하면 알람이 즉시 발생됩니다.

올바른 날짜와 시간을 설정하기 만하면됩니다. 사실, set_alarm() 함수에 전달한 매개 변수를 사용해야합니다.

(출처 : http://developer.android.com/reference/android/app/AlarmManager.html#set(int, long, android.app.PendingIntent)

+0

오 감사합니다! 무슨 실수 ... :) –

+0

당신은 환영합니다;) 그냥 대답을 받아 들일 수 있습니다. 고맙습니다 :) – mithrop