I want to call a thread in android activity after a time interval like 5 or 10 mins. after that i want to send an automatic SMS in android, to any number. Please help me. I have idea about thread that we can do with this but the problem with that function is, it is calling over and over again. Thanks in advance
Its just that code. But it once calls, then sends sms repeatedly until we stop application. Please help me.
Thread timer = new Thread()
{
@Override
public void run()
{
try
{
sleep(1000*60*2);
}
catch (InterruptedException ex)
{
ex.printStackTrace();
}
finally
{
String phone_number = "123456789"; // some phone number here
String text =
"Hello this is an automatic SMS service informing you about the current status: \n" +
" City :" +cityName +"\n"
+"State :" +stateName+"\n"
+"Country :" +countryName +"\n";
SmsManager smsMgr = SmsManager.getDefault();
smsMgr.sendTextMessage(phone_number, "Hussnain Muavia", text, null, null);
txtLat.setText("SMS Sent");
}
}
};
timer.start();