【问题标题】:How can i get the repeat alarm for week days using alarm manager?如何使用警报管理器获得工作日的重复警报?
【发布时间】:2023-03-23 07:52:02
【问题描述】:

您好,我正在开发警报应用程序,我需要在用户选择的不同日期在同一时间重复调用警报。

如果我将闹钟时间设置为 8PM 并将选项重复设置为 sundaytuesday 将在每个 sundaytuesday 上调用闹钟。

任何帮助将不胜感激。

【问题讨论】:

    标签: android facebook


    【解决方案1】:

    为此使用广播接收器和 Sqlite 数据库。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-19
      相关资源
      最近更新 更多