我怎样才能使用报警经理周天重复报警? [英] How can i get the repeat alarm for week days using alarm manager?
本文介绍了我怎样才能使用报警经理周天重复报警?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好我开发的应用程序报警,我需要反复调用报警的同时由用户选择不同的日子。
Hi i am developing alarm application for that i need to invoke alarm repeatedly for the same time in different days selected by the user.
我meen如果我设置报警时间为晚上8点
并作为日
,周二
警报将在每个周日援引
,周二
。
what i meen if i set alarm time as 8PM
and repeat option as sunday
, tuesday
the alarm will be invoked on every sunday
, tuesday
.
任何帮助将是AP preciated。
Any help would be appreciated.
推荐答案
使用广播接收器和SQLite数据库为。
Use Broadcast Receiver and Sqlite Database for that.
public class MyReceiver extends BroadcastReceiver {
DBAdapter mDba;
SQLiteDatabase mDb;
Ringtone rt;
MediaPlayer mp;
AlertDialog.Builder alertbox;
Context ctx;
@Override
public void onReceive(Context context, Intent intent) {
DBHelper mDbh = new DBHelper(context, null, null, 1);
mDb = mDbh.getWritableDatabase();
mDb.setLockingEnabled(true);
mDba = new DBAdapter(context);
mDba.open();
Cursor cr = mDb.query("mReminderEntry", null, null, null, null,
null, null);
if (cr.equals(null)) {
System.out.println("No Data Found");
} else {
Date d = new Date();
Calendar calendar = Calendar.getInstance();
int day = calendar.get(Calendar.DAY_OF_WEEK);
String today = null;
if (day == 2) {
today = "Monday";
} else if (day == 3) {
today = "Tuesday";
} else if (day == 4) {
today = "Wednesday";
} else if (day == 5) {
today = "Thursday";
} else if (day == 6) {
today = "Friday";
} else if (day == 7) {
today = "Saturday";
} else if (day == 1) {
today = "Sunday";
}
int system_hour = d.getHours();
int system_minute = d.getMinutes();
cr.moveToFirst();
for (int i = 0; i < cr.getCount(); i++) {
if (cr.getString(3).equals(system_hour + ":" + system_minute)
&& cr.getString(1).equals("Daily")) {
Intent scheduledIntent = new Intent(context, MyScheduledActivity.class);
scheduledIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(scheduledIntent);
break;
} else if (cr.getString(3).equals(
system_hour + ":" + system_minute)
&& cr.getString(1).equals(today)) {
Intent scheduledIntent = new Intent(context, MyScheduledActivity.class);
scheduledIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(scheduledIntent);
break;
} else {
System.out.println("No Matching");
}
cr.moveToNext();
}
}
cr.close();
mDba.close();
}
}
这篇关于我怎样才能使用报警经理周天重复报警?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文