I am developing an application where I need to send an SMS to a particular phone number. I can send SMS using the following code.
try {SmsManager smsManager = SmsManager.getDefault (); SmsManager.sendTextMessage (phone no, zero, SMS, empty, empty); Toast. Make text (getApplicationContext (), "SMS sent!", Toast. LNNHHLog). Show (); } Hold (exception e) {toast. Make text (getApplicationContext), "SMS fail, please try again later!", Toast.LnnGH_LOG). Show (); E.printStackTrace (); } Now that I want the SMS should go automatically. The time on which the message should be sent automatically, is stored in the MySQL database. So I need the code that will check that time and then send the message to that number automatically. This is a kind of reminder that the user will keep a reminder in the application eg After 1 hour I have to receive a message so the message should arrive after 1 hour. PLJ help ??
Finally I got it.
/ ** The code for the reminder is here * / int time = integer. Paracet (answer); Int num = (int) System.currentTimeMillis (); Intent = intent (getApplication (), MyBroadcastReceiver.class); Intent.putExtra ("phoneNo", phoneNo); Calendar Calendar = Calendar.getInstance (); Calendar.setTimeInMillis (System.currentTimeMillis ()); Calendar.ad (calendar minutes, time); Pending Vertical Vertical = Pending Intent. GetBrastro (getApplicationContext (), Number, Intent, 0); AlarmManager AlarmManager = (AlarmManager) getSystemService (ALARM_SERVICE); AlarmManager.Set (AlarmManager.rTC_wekup, System.contentimemiliss (+) calendar.getTimeInMillis (), pending transplantation); Toast. MakeApplication (), "Alarm Set In" + Time + "Minute", Toast. LNNGHHORT). Show (); / ** The code for the reminder is finished * / and my receiver code is
response to the public blank (reference reference, intent to intent ) {String sms = "your turn is coming, please be ready thanks."; No string phone; Bundle Extrasbundle = Intent. Gate ActaStras (); PhoneNo = extrasBundle.getString ("phoneNo"); {Try smsManager smsManager = SmsManager.getDefault (); SmsManager.sendTextMessage (phone no, zero, SMS, empty, empty); Toast. Make Text (Reference, "Sent to SMS" + Phone No, Toast. LNNH_LANG). Show (); } Hold (exception e) {toast. Make text (context, "SMS failed, please try again later!", Toast.LnnnH_LANG). Show (); E.printStackTrace (); } }
Just someone can require it ... Thanku
Use this for a purpose Create a receiver, register it in the manifest file. Set an alarm after a special time with Alarma Manager. Receive your SendSMS code in the recipient.
EDIT: I have answered this for a long time, it is not suitable for current scenarios, please read this blog for a better option instead.
Comments
Post a Comment