我有以下代码(缩写为相关部分)。如果我在特定时间设置了警报管理器,并且在此时间到来时通知未显示。我想像sun-mon-tue一样设置日期。
Code Snippet :
public class service extends Service {
private int Period_You_Want_in_MilliSecond = 30 * 1000;
Calendar calender ;
SimpleDateFormat format ;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
DataBase DB=new DataBase(this);
//get row from database where id=1
final CourseClass C=DB.getCousre(1);
calender = Calendar.getInstance();
format = new SimpleDateFormat("hh:mm aa");
Toast.makeText(getApplicationContext(), "service entered", Toast.LENGTH_LONG).show();
final Handler h = new Handler();
Runnable r = new Runnable() {
@Override
public void run() {
String current_time = format.format(calender.getTime());
//Toast.makeText(getApplicationContext(), ""+current_time,Toast.LENGTH_LONG).show();
//check if the row reterned if filed name has data lenght>0 return True
if(C.getName().length()>0){
if(current_time.equals("01:24 PM")){
//Toast.makeText(getApplicationContext(), "TIMER",Toast.LENGTH_LONG).show();
show_notification();
}
}
h.postDelayed(this,Period_You_Want_in_MilliSecond);
}
};
h.post(r);
return super.onStartCommand(intent, flags, startId);
}
}