Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send SMS programmatically on scheduled time

Tags:

android

Is there any way to send SMS programmatically on scheduled time ? Without checking current time in every second.

like image 381
Big.Child Avatar asked Aug 08 '26 10:08

Big.Child


1 Answers

Use the Android Timer class' schedule method to schedule the sms to be sent using something like the following in the run() method of the scheduled TimerTask:

SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, null, null);

For a formatted date string, to get the when argument of the schedule() function, use the SimpleDateFormat class' parse() method. If your date string is "12/31/2013-12:12", then you can get the date object using:

SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy-HH:mm");
Date when = sdf.parse(yourDateString, 0);

Other options for the SimpleDateFormat are here.

like image 129
varevarao Avatar answered Aug 09 '26 23:08

varevarao



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!