I am using time picker for my app which sends sms based on a particular time in future. I have the sms sending part ready using sms manager. I also have the user time using getCurrentHour() and getCurrentMinute(). This is my code
if(phoneNo.length()>0&&message.length()>0)
{
sendSMS(phoneNo,message);
}
else
{
Toast myToast=Toast.makeText(getBaseContext(),"Please enter both phone number and message.",Toast.LENGTH_SHORT);
myToast.show();
}
}
});
}
How do I proceed to send the sms at a particular time?
You’ll need to move your
sendSms()method in to a Service, and then use AlamManager to cause your Service to be woken at the correct time, and send your SMS.You will need to define your Service:
You’ll need declare this service in your manifest:
Finally you’ll need to set the alarm which will wake up at the given time and send your message:
This will need to be called from within an Activity or Service which has either extends or has access to a Context.