0

I have an application that sends a delayed text. I call it by:

Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
long delay = cal.getTimeInMillis();
smsControl.sendSMSLater(phoneNumber, msg, (date - delay));

and the rest is:

class smsControl {

static ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);

public static void sendSMSLater(final String phoneNumber, final String msg, long date) {
    ScheduledFuture scheduledFuture = scheduledExecutorService.schedule(new Callable() {
        public Object call() throws Exception {
            SmsManager smsManager = SmsManager.getDefault();
            String smsNumber = phoneNumber;
            String smsText = msg;
            smsManager.sendTextMessage(smsNumber, null, smsText, null, null);
            return "Sent!";
        }
    }, date, TimeUnit.MILLISECONDS);

}

}

The problem is it does not wait the delayed time date. It sends it very shortly after. Any insight helps! Thanks!

Treeloy
  • 41
  • 5
  • How do you calculate the date in `smsControl.sendSMSLater(phoneNumber, msg, (date - delay));` – Louth May 08 '12 at 03:07
  • The date is a stored time the user enters through DatePicker and then I convert it to a long. The delay should be the current time. `code`cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); cal.set(Calendar.YEAR, mYear); cal.set(Calendar.MONTH, mMonth); cal.set(Calendar.DAY_OF_MONTH, mDay); cal.set(Calendar.HOUR_OF_DAY, tpResult.getCurrentHour()); cal.set(Calendar.MINUTE, tpResult.getCurrentMinute()); cal.set(Calendar.SECOND, 0); editdate = cal.getTimeInMillis()`code` – Treeloy May 08 '12 at 03:08
  • 1
    Try logging the value of `(date - delay)` to see what that calculation gives you. – Louth May 08 '12 at 03:27
  • Hmm I think there lies the problem, my date seems to be 7hours behind so I am getting a negative offset. Time to see why im getting a time difference even though theyre both initialized to UTC. Thanks for the help! – Treeloy May 08 '12 at 03:49

0 Answers0