java - Logical issue in list of numbers in the call log -


my app gives list of numbers in call log.

unfortunately, encountered small issue. app lists numbers below separately (even though they're same number). there way group 1 number in app? i'd apply method numbers countries.

example:

754-3010 (local)

(541) 754-3010 (domestic)

+1-541-754-3010 (international)

1-541-754-3010 (dialed in us)

001-541-754-3010 (dialed germany)

code app:

cursor managedcursor = managedquery( calllog.calls.content_uri,null, null,null, null);  int number = managedcursor.getcolumnindex( calllog.calls.number );  list<string> list = new arraylist<>();       while ( managedcursor.movetonext() ) {             string phnumber = managedcursor.getstring( number );             list.add(phnumber); } 

i show list in app.

i assuming numbers belong usa

you need convert numbers standard format in list while iterating.

set<string> numset = new hashset<string>();  while ( managedcursor.movetonext() ) {     string phnumber = managedcursor.getstring( number );      //remove non-numeric characters     phnumber = phnumber.replaceall("[^\\d]", "");      //remove leading 0s     phnumber = phnumber.replacefirst("^0+(?!$)", "");      //remove "1" number if size 11     phnumber = phnumber.length() == 11 ? phnumber.substring(1,phnumber.length());      //format number     phnumber = phnumber.replacefirst("(\\d{3})(\\d{3})(\\d+)", "($1) $2-$3");      //check if set has number, else put     if(numset.get(phnumber) == null) numset.put(phnumber); } 

if numbers not limited usa, need write logic support other countries.

refer this post has similar requirement.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -