我正在为学校创建一个待办事项应用程序。当一个人输入项目的日期和时间时,应用程序应该创建一个在指定时间发出的通知。但是,当应用程序运行时,通知会在项目创建时关闭,而不是在指定的时间。附上我的通知方法。
static final int uniqueid = 139868;
@SuppressLint("NewApi")
public void sendNotification(String title, String body){
try{
Log.i("LIST", "inside sendNotification");
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Intent intent = new Intent(this,ItemEditorActivity.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
//set notification for date set
Notification n = new Notification.Builder(this)
.setContentTitle(title)
.setSmallIcon(R.drawable.ic_launcher)
.setWhen(dateAndTime.getTimeInMillis())
.setTicker(body)
.addAction(R.drawable.ic_launcher, title, pi)
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.build();
Log.i("LIST", dateAndTime.toString());
Log.i("LIST", "notify");
nm.notify(uniqueid, n);
} catch (Exception e){
e.printStackTrace();
}
}
在哪里private Calendar dateAndTime=Calendar.getInstance();