Android Studio:设置特定日期和时间的提醒

Android Studio: Set reminder for specific date and time

我是一名高中生,我大大低估了全神贯注于 android 工作室的难度。经过 3 个月的努力,我已经设法解决了大部分问题,但我还有一件重要的事情需要完成:

我需要为用户定义的日期和时间设置提醒,该提醒将显示为通知或其他内容。我已经尝试了那里的所有教程,但我真的不知道我在做什么。在这一点上,我只需要有人一步一步地引导我完成它,因为我已经束手无策并且后悔曾经尝试过这个项目。

如有任何帮助,我们将不胜感激。

试试这个:

final static int req1=1;
public String a = "0"; // initialize this globally at the top of your class.

private void setAlarm(Calendar target){   
    Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), req1, intent, 0);
    AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
    alarmManager.set(AlarmManager.RTC_WAKEUP, target.getTimeInMillis(), pendingIntent);
    a ="1";
}

调用此方法:

Calendar cal = Calendar.getInstance();
cal.set(2016, 0, 23, 18, 5, 0);
setAlarm(cal);
if(a.equals("0")
{
  // do whatever you want to do.  
}