1

请指导我,以便警报(邮件发送)在事件发生前 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);
4

1 回答 1

1

我认为你应该使用setRepeating方法AlarmManager而不是set方法。

am.setRepeating(type, triggerAtMillis, intervalMillis, operation);
于 2012-11-01T11:21:00.770 回答