2013-01-04 106 views
0

我想設置一個鬧鐘管理器,這樣我的應用程序每個星期天都會發出通知,但我似乎無法得到它。這裏是我的代碼:鬧鐘管理器和通知Android

此代碼是在一個名爲「StatusOfChild.java」類的onCreate方法

Intent myIntent = new Intent(StatusOfChild.this , myService.class);  
    AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE); 
    PendingIntent pendingIntent = PendingIntent.getService(StatusOfChild.this, 0, myIntent, 0); 

    Calendar calendar = Calendar.getInstance(); 
    calendar.set(Calendar.DAY_OF_WEEK, 1); 
    calendar.set(Calendar.HOUR_OF_DAY, 12); 
    calendar.set(Calendar.MINUTE, 00); 
    calendar.set(Calendar.SECOND, 00); 

    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 24*60*60*1000 , pendingIntent); //set repeating every 24 hours 

此代碼是在一個名爲「myService.java」

public class myService extends IntentService{ 

public myService(){ 
    super("myService"); 
} 


@Override 
protected void onHandleIntent(Intent intent) { 
    // TODO Auto-generated method stub 
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    Notification notify = new Notification(R.drawable.main1,"Its Time to Eat",1000); 

    Context context = myService.this; 
    CharSequence title = "Its Time to Eat"; 
    CharSequence details = "Click Here to Search for Restaurants"; 
    Intent myIntent = new Intent(context,StatusOfChild.class); 
    PendingIntent pending = PendingIntent.getActivity(context, 0, myIntent, 0); 
    notify.setLatestEventInfo(context, title, details, pending); 
    nm.notify(0,notify); 
} 

}

回答

0

在日曆(日曆)中,您需要設置MONTH和YEAR。請以適當的格式(數據和時間格式)打印日曆的值;以便您知道您爲alarmManager設置的時間。

+0

即使我想讓通知重複每個月的每個星期,我是否必須設置特定的月份和年份? – Shane