我怎样才能使用报警管理器的Andr​​oid工作日重复报警? [英] how can i get the repeat alarm for week days using alarm manager in android?

查看:123
本文介绍了我怎样才能使用报警管理器的Andr​​oid工作日重复报警?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我是新到Android我开发我需要反复调用报警的同时由用户选择不同的日子报警的应用程序。我meen如果我设置报警时间为上午10点至周日,周一,周六警报将在每个周日,周一援引,周六。

Hi i am new to android i am developing alarm application for that i need to invoke alarm repeatedly for the same time in different days selected by the user. what i meen if i set alarm time as 10AM and repeat option as sunday, monday, saturday the alarm will be invoked on every sunday,monday,saturday.

在这里,我现在用的是code调用报警

Here i am using the code to invoke the alarm

AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
                Intent intent = new Intent(Alarm.this, OneShotAlarm.class);  //here i am calling broad \cast receiver to invoke alarm

                 PendingIntent sender = PendingIntent.getBroadcast(Alarm.this, requestCode, intent, 0);
                 Calendar calendar = Calendar.getInstance();
calendar.set(Calender.HOUR_OF_DAY,10); 
                am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);

通过使用这种$ C $词时调用present一天10 AM.But我戈莱是需要在上午10点至调用报警选定天。

By using this code i am invoking present day at 10AM.But my gole is need to invoke the alarm for selected days at 10AM.

在这里,我有一个问题请大家帮忙为此也。当我试图把经过的时间,报警将被当前时间调用。我怎么可以给过去的时光。我的意思是当我在11AP,我需要给上午9点。

Here i have another question please help for this also. When i am trying to put the passed time the alarm will be invoked for the current time. How can i give the past time. i mean when i am at 11AP i am need to give 9AM.

请给我建议,如果有什么办法。 先谢谢了。

Please suggest me if there is any way. Thanks in advance.

推荐答案

请写低于code在广播接收器类,它会解决你的问题。

Please Write below Code in your Broadcast Receiver Class, it will solve your problem.

public class MyBroadcastReceiver 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();
            System.out.println("Current Hour is:- " + d.getHours());
            System.out.println("Current Minute is:- " + d.getMinutes());
            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";
            }
            System.out.println("Today is:- " + today);

            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")) {

                    System.out.println("Matched");
                    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);

                    System.out.println("Matched");

                    break;
                } else {
                    System.out.println("No Matching");
                }
                cr.moveToNext();
            }
        }
        cr.close();
        mDba.close();
    }
}

如果u有关于该再告诉我任何问题。

If U have any issue regarding that then tell me.

这篇关于我怎样才能使用报警管理器的Andr​​oid工作日重复报警?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆