警报广播类不会再次重复警报

时间:2012-11-01 09:30:35

标签: android alarmmanager

请指导我,以便警报(邮件发送)将再次编译,并在事件发生1天之前,然后在事件发生30分钟之前向我发送邮件。

先谢谢。

public class MailAlarm extends BroadcastReceiver{

    NotificationManager nm;

    public void onReceive(Context context, Intent intent) {

        nm = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

        //int iUniqueId = (int) (System.currentTimeMillis() & 0xfffffff);

        String event = Mail_Fill_Details.Discripton;
        String name = Mail_Fill_Details.Person_Name;
        String mail =Mail_Fill_Details.mailString;
        try {   
            GMailSender sender = new GMailSender("taskschedulerfable@gmail.com", "xyz");
            sender.sendMail("Reminder of "+event+" ("+name+")" ,   
                    "REMINDER!! REMINDER!! REMINDER!! \n\n\nYou got a reminder about "+event+"("+name+") after 5 minutes\n\n\n",   
                    "taskschedulerfable@gmail.com",   
                    mail);   
        } catch (Exception e) {   
            Log.e("SendMail", e.getMessage(), e);   
        }

休息代码在这里......

Intent intent = new Intent(Mail_Fill_Details.this,
                                MailAlarm.class);
                        Bundle b12 = new Bundle();

                        b12.putString("serverresponse", Discripton);
                        b12.putString("serverresponse1", Person_Name);
                        b12.putString("serverresponce2", mailString);

                        intent.setAction("" + Math.random());
                        intent.putExtras(b12);
                        PendingIntent displayIntent = PendingIntent
                                .getBroadcast(Mail_Fill_Details.this,
                                        iUniqueId, intent,
                                        PendingIntent.FLAG_UPDATE_CURRENT);
                        alarmManager.set(AlarmManager.RTC_WAKEUP,
                                calendar.getTimeInMillis() - 300000,
                                displayIntent);
                        // alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
                        // calendar.getTimeInMillis(), 20, displayIntent);

1 个答案:

答案 0 :(得分:1)

我认为您应该使用setRepeating AlarmManager方法代替set方法。

am.setRepeating(type, triggerAtMillis, intervalMillis, operation);