我创建了活动。我想在事件开始时间的10分钟之前设置通知。
我在谷歌日历中看到他们已经设置了这样。
如何将日历设置为事件发生前的时间?
我在这里获取日历实例并设置日历。
public void notification(Calendar c)
{
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DATE);
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
cal.set(Calendar.HOUR_OF_DAY, hour);
cal.set(Calendar.MINUTE, minute);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.set(Calendar.DATE, day);
notification = c.getTime();
notificationTime = df.format(notification);
// notifyTime.setText(notificationTime);
Toast.makeText(getApplicationContext(), String.valueOf(notification), Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getBaseContext(),NotificationReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), RQS_1, intent, 0);
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(),
AlarmManager.INTERVAL_DAY *7, pendingIntent);
ComponentName receiver = new ComponentName(getApplicationContext(),NotificationReceiver.class);
PackageManager pm = getApplicationContext().getPackageManager();
pm.setComponentEnabledSetting(receiver,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
}
谢谢..