通过调用系统日历的方式在软件里面实现事件的提醒功能,这个就可以设置到具体的年月日的信息;
具体实现代码:
try {SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式Date date = formatter.parse(metxiqing.getText().toString()+"00:00:00");long timeInfor = date.getTime();Intent intent=new Intent(this,AlarmReceiver.class);intent.setAction("something");intent.setType("something");intent.setData(Uri.EMPTY);intent.addCategory("something");intent.putExtra("ids",entry.getRepMsg());// 以上给intent设置的四个属性是用来区分你发给系统的闹钟请求的,// 当你想取消掉之前发的闹钟请求,这四个属性,必须严格相等,所以你需要一些比较独特的属性,比如服务器返回给你的json中某些特定字段。//当然intent中也可以放一些你要传递的消息。PendingIntent pendingIntent=PendingIntent.getBroadcast(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);//alarmCount是你需要记录的闹钟数量,必须保证你所发的alarmCount不能相同,最后一个参数填0就可以。AlarmManager am=(AlarmManager)this.getSystemService(this.ALARM_SERVICE);am.set(AlarmManager.RTC_WAKEUP, timeInfor, pendingIntent);//这样闹钟的请求就发送出去了。time是你要被提醒的时间,单位毫秒,注意不是时间差。第一个参数提醒的需求用我给出的就可以,感兴趣的朋友,可以去google一下,这方面的资料非常多,一共有种,看一下就知道区别了。//System.currentTimeMillis()是获取系统时间 ,+120000是120秒即两分钟后提醒
}catch (Exception e){e.printStackTrace();
}