我尝试构建闹钟,并在SQLite DB中设置唤醒时间
我已经有时间从DB
获得毫秒但它当时没有发出警报
我认为这可能是一种糟糕的方法,如果有更好的方法请告诉我
以下是我的数据库课程
public Cursor filList(long id) throws SQLException{
Cursor cursor = db.query(
"ALARM",
new String[] {"_id","Atime"},
"_id =" +id,
null,
null,
null,
null,
null
);
if (cursor != null) {
cursor.moveToFirst();
}
return cursor;
}
public int update(long rowId, String value) {
ContentValues args = new ContentValues();
args.put("Atime", value);
return db.update("ALARM", //資料表名稱
args, //VALUE
"_id=" + rowId, //WHERE
null //WHERE的參數
);
}
public boolean isEmpty(){
db.execSQL("CREATE TABLE IF NOT EXISTS"+ " ALARM " +"(_id INTEGER PRIMARY KEY , " + "Aname VAR UNIQUE , " +"Atime TIME)");
Cursor cursor = db.query(
"ALARM",
null,
null,
null,
null,
null,
null,
null
);
if (cursor.getCount() ==0) {
return false; //將指標移到第一筆資料
}
else
return true;
}
以下是从DB
获取数据 if(helper.isEmpty()){
Cursor morn = helper.filList(1);
Cursor noo = helper.filList(2);
Cursor ni = helper.filList(3);
Cursor mid = helper.filList(4);
alarm(morn.getString(1));
alarm(noo.getString(1));
alarm(ni.getString(1));
alarm(mid.getString(1));
}
以下是闹钟
public void alarm (String alarmtimein) {
SimpleDateFormat time = new SimpleDateFormat("yyyy MM dd HH:mm");
SimpleDateFormat date = new SimpleDateFormat("yyyy MM dd");
try {
Intent intent11 = new Intent(getApplicationContext(), PlayReceiver.class);
Date today = new Date();
String s = date.format(today);
String times = s + " " + alarmtimein;
Date alarmtimeout = time.parse(times);
long milliseconds = alarmtimeout.getTime();
intent11.putExtra("msg", "play_voice");
long elapsed = milliseconds;
PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext(), 1, intent11,
PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP,elapsed , pi);
} catch (ParseException e) {
e.printStackTrace();
}
}
答案 0 :(得分:0)
尝试用setExact替换set方法。
grammar ExpAnalyser;
//Infix Arithmetic
eval : additionExp;
additionExp : multiplyExp(PLUS multiplyExp | MINUS multiplyExp)* ;
multiplyExp : unaryExp(MULT unaryExp | DIV unaryExp)* ;
unaryExp : MINUS atomExp | atomExp ;
atomExp : NUMBER | LPAREN eval RPAREN ;
//Tokenizers : Lexers
MULT : '*' ;
DIV : '/' ;
MOD : '%' ;
PLUS : '+' ;
MINUS : '-' ;
LPAREN : '(' ;
RPAREN : ')' ;
NUMBER : [0-9]+ (['.'][0-9]+)? ;
COMMENT : '//' .+? ('\n'|EOF) -> skip ;
WS : [ \t\r\n]+ -> skip ;