[英]AlarmManger with show notification on specific time
I have the following code (abbreviated to the relevant part). 我有以下代码(缩写为相关部分)。 If I set the alarm manger on a specific time and when this time comes the notification doesn't show up.
如果我在特定时间设置了警报管理器,并且在该时间到来时,通知不会显示。 I want to set date like 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);
}
}
You are not using the AlarmManager, you are using a Handler. 您没有使用AlarmManager,而是使用了处理程序。 Take a look at this example.
看一下这个例子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.