我正在设置一个闹钟管理器,所以我的应用程序会在每个星期天发出通知,但我似乎无法得到它。这是我的代码:
此代码位于名为“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 :(得分:0)
在日历(日历)中,您需要设置MONTH和YEAR。请以适当的格式(数据和时间格式)打印日历的值;这样您就知道为alarmManager设置的时间。