extracting content of an sms in android app -
i coding app in on receive of sms content of sms should extracted , split string 2 parts , in separate variable. here have tried. code doesn't work though there no errors.
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(); // string[] arr=message.split(","); stringtokenizer tokenizer = new stringtokenizer(message, ","); toast toast1 = toast.maketext(context, "tokenizer", toast.length_short); toast1.show(); int numberoftokens = tokenizer.counttokens(); string[] splitarr = new string[numberoftokens]; splitarr[0] = tokenizer.nexttoken(); splitarr[1] = tokenizer.nexttoken(); toast toast3 = toast.maketext(context, splitarr[0], toast.length_short); toast3.show(); toast toast2 = toast.maketext(context, "split", toast.length_short); toast2.show(); string lat=splitarr[0]; string lng=splitarr[1]; double lat1=double.valueof(lat); double lng1=double.valueof(lng); }} }
Comments
Post a Comment