android read sms programmatically -
i try read sms broadcastreciver. searched , wrote code:
public class incomingsms extends broadcastreceiver { // object of smsmanager final smsmanager sms = smsmanager.getdefault(); public void onreceive(context context, intent intent) { // retrieves map of extended data intent. final bundle bundle = intent.getextras(); try { if (bundle != null) { final object[] pdusobj = (object[]) bundle.get("pdus"); (int = 0; < pdusobj.length; i++) { smsmessage currentmessage = smsmessage.createfrompdu((byte[]) pdusobj[i]); string phonenumber = currentmessage.getdisplayoriginatingaddress(); string sendernum = phonenumber; string message = currentmessage.getdisplaymessagebody(); log.i("smsreceiver", "sendernum: "+ sendernum + "; message: " + message); int duration = toast.length_long; toast toast = toast.maketext(context, "sendernum: "+ sendernum + ", message: " + message, duration); toast.show(); } // end loop } // bundle null } catch (exception e) { log.e("smsreceiver", "exception smsreceiver" +e); } }
in broadcast receiver can show income messages in toast, don't need it. need concret sms. example, need read sms, has received user +4423232 need read numbers(users) sms
how can solve problem?
simply user's ph. no getting ph. no programmatically or ask him , use if statement find out if message required number , whatever want jakar said. issue if know how use try
statement why can't use if
statement?
Comments
Post a Comment