gpt4 book ai didi

android - 如何在 android 中每周安排闹钟?

转载 作者:太空狗 更新时间:2023-10-29 15:05:38 25 4
gpt4 key购买 nike

我想根据所需的日期安排闹钟周日、周二、周四。我已经根据时间安排了它,但不能像工作日那样做。

代码如下:

private void StartScheduler(Context context) {

Calendar startTimmer = Calendar.getInstance();
startTimmer.setTimeZone(TimeZone.getDefault());
startTimmer.set(Calendar.HOUR_OF_DAY,sHour);
startTimmer.set(Calendar.MINUTE,sMinute);
startTimmer.set(Calendar.SECOND,00);

AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent StartAlarmTime = new Intent(Schedule_details.this, MyAlaramStartReceiver.class);
PendingIntent pendingIntent1 = PendingIntent.getBroadcast(context, 0, StartAlarmTime, 0);

alarmManager.set(AlarmManager.RTC_WAKEUP, startTimmer.getTimeInMillis(),pendingIntent1);
Log.d("<<My-Start-Alarm>>", "ALARM Set To Start At: " + startTimmer.getTime().toLocaleString());
}

最佳答案

这里是答案:

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();
}

关于android - 如何在 android 中每周安排闹钟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22221432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com