How to Know which Sms is sent/delivered from Android BroadcastReceiver? -
hi guys have made simple app send multiple sms on android, , cannot find known sms sent/delivered, because delivery notification not tell is.
here code :
this.destination = data[0]; this.body = data[1]; pendingintent pisend = pendingintent.getbroadcast(actx, 0, new intent(cons.sms_sent),0); pendingintent pidelivered = pendingintent.getbroadcast(actx, 0, new intent(cons.sms_delivered), 0); smsmanager smsmanager = smsmanager.getdefault(); smsmanager.sendtextmessage(destination, null, body, pisend, pidelivered);
then use broadcast receiver delivery status
public class deliversmsbroadcastreceiver extends broadcastreceiver { @override public void onreceive(context context, intent intent) { switch (getresultcode()) { case activity.result_ok: toast.maketext(context, "sms delivered", toast.length_short).show(); log.d(cons.tags+" rk","result_ok=> deliver"); break; case activity.result_canceled: toast.maketext(context, "sms not delivered", toast.length_short).show(); log.d(cons.tags+" rk","result_canceled"); break; }} }
and here activity :
public class senderpage extends activity { private edittext txtrecepients = null; private edittext inputsmstext = null; private button btnsendsms = null; private final broadcastreceiver outgoingsmsbr = new outgoingsmsbroadcastreceiver(); private final broadcastreceiver deliversmsbr = new deliversmsbroadcastreceiver(); @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.senderpage); log.i(cons.tags, "sender page start"); this.settitle("send message"); this.txtrecepients = (edittext) findviewbyid(r.id.txtrecepients); this.inputsmstext = (edittext) findviewbyid(r.id.inputsmstext); this.btnsendsms = (button) findviewbyid(r.id.btnsendsms); txtrecepients.settext("087722079905"); //087722079905 //081214571542 btnsendsms.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { //toast.maketext(senderpage.this, "clicked send", toast.length_short).show(); string txtrecepients = senderpage.this.txtrecepients.gettext().tostring(); string inputsmstext = senderpage.this.inputsmstext.gettext().tostring(); new sender(senderpage.this,cons.tags).execute(txtrecepients, inputsmstext); } }); //txtrecepients.gettext().tostring(); } @override protected void onresume() { registerreceiver(outgoingsmsbr, new intentfilter(cons.sms_sent)); registerreceiver(deliversmsbr, new intentfilter(cons.sms_delivered)); super.onresume(); } @override protected void onpause() { unregisterreceiver(outgoingsmsbr); unregisterreceiver(deliversmsbr); super.onpause(); }
}
and problem when sent more 1 sms delivery information cannot make sure sms delivered ?
finally got answer added intent extras pending intent sms create datetime, update sms status based on datetime sent extras data, here snippet :
intent sentintent = new intent(cons.sms_sent); sentintent.putextra("createdtime", createdtime); intent deliveryintent = new intent(cons.sms_sent); deliveryintent.putextra("createdtime", createdtime);
then can identify sms sent/delivery created time
public void onreceive(context context, intent intent) { string smsdatetimeasid = intent.getstringextra("createdtime"); }
Comments
Post a Comment