android - Selected SMS by keyword to Listview -
how select sms keyword body listview?
current progress: sms shown in listview, sms displayed. want display selected sms keyword. code.
public list<string> getsms() { list<string> list = new arraylist<string>(); uri urismsuri = uri.parse("content://sms/inbox"); cursor cursor = null; try { cursor = getcontentresolver().query(urismsuri, null, null, null, null); } catch (exception e) { e.printstacktrace(); } try { (boolean hasdata = cursor.movetofirst(); hasdata; hasdata = cursor .movetonext()) { string body = cursor.getstring(cursor.getcolumnindex("body")); list.add(body); } } catch (exception e) { e.printstacktrace(); } return list; }
if add body content listview, why not compare keyword before adding?
string keyword = "hello" try { (boolean hasdata = cursor.movetofirst(); hasdata; hasdata = cursor .movetonext()) { string body = cursor.getstring(cursor.getcolumnindex("body")); if(body.tolowercase().contains(keywoed.tolowercase())) list.add(body); } } catch (exception e) { e.printstacktrace(); }
i have used tolowercase()
case insensitive compare.
hope helps.
Comments
Post a Comment