android - Finding which phone contacts are users in Parse -


in application, each user signs in phone number. in other words, each username corresponds different number. want detect phone contacts using application in way. however, not determine how should this. @ first, think querying each contact , users_in_contacts using or query @ end. method given in this answer:

public void getfriends(list<string> numbers) {     list<parsequery<parseuser>> queries = new arraylist<parsequery<parseuser>>();     (string number : numbers) {         parsequery<parseuser> parsequery = parseuser.getquery();         parsequery.whereequalto("username", number);         queries.add(parsequery);     }      parsequery<parseuser> userquery = parsequery.or(queries);      userquery.findinbackground(new findcallback<parseuser>() {          @override         public void done(list<parseuser> numberlist, parseexception e) {             if (e == null) {                 (int = 0; < numberlist.size(); i++) {                     log.v("" + + ". user_contact", numberlist.get(i).getusername());                 }             }         }     }); } 

it working solution not want burst many queries , exceed limit of request per second. thus, want know there better alternative or not.

in short, how can achieve find users in contacts fast , costless (with respect request per second) possible? ears every advice , alternative ways comes you. thank in advance.

there querying method named .wherecontainedin() in parse. using query, can users in contracts without using other query. put of contracts (which associated phone number) parameter in method , worked. wrote asynctask perform these operations , monitor results in listview. if give advice increase performance of task, appreciate it.

public class retrievecontacteduserstask extends asynctask<string, void, string> {      private activity activity;     hashmap<string, string> contactsmap = new hashmap<>();     string[] contactedusernumbers;     listview contactsview;       public retrievecontacteduserstask (activity activity, listview contactsview) {          this.activity = activity;         this.contactsview = contactsview;     }      @override     protected string doinbackground(string... params) {          retrievecontactlist();         return "executed";     }      @override     protected void onpostexecute(string result) {          treemap<string, string> contactedusersmap = new treemap<>();          (int = 0; < contactedusernumbers.length; i++) {             contactedusersmap.put(contactsmap.get(contactedusernumbers[i]), contactedusernumbers[i]);         }          contactsview.setadapter(new contactadapter(activity, contactedusersmap));     }      @override     protected void onpreexecute() {}      @override     protected void onprogressupdate(void... values) {}      public void retrievecontactlist() {          cursor phones = null;          try {             phones = activity.getcontentresolver().query(contactscontract.commondatakinds.phone.content_uri, null, null, null, null);             while (phones.movetonext())             {                 string _number = phones.getstring(phones.getcolumnindex(contactscontract.commondatakinds.phone.number)).replaceall("\\s+", "");                 string _name = phones.getstring(phones.getcolumnindex(contactscontract.commondatakinds.phone.display_name));                  contactsmap.put(_number, _name);             }             phones.close();          } catch ( exception e ) {}          {             if(phones != null){                 phones.close();             }         }          try {             retrievecontactedusers(contactsmap);         } catch (parseexception e) {             e.printstacktrace();         }     }      public void retrievecontactedusers(map<string, string> numbers) throws parseexception {         parsequery<parseuser> query = parseuser.getquery();         query.wherecontainedin("username", numbers.keyset());          list<parseuser> users= query.find();         contactedusernumbers = new string[users.size()];         (int = 0; < users.size(); i++) {             string value = users.get(i).getusername();             contactedusernumbers[i] = value;         }     } } 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -