如何比较两种不同的数据?

时间:2015-08-25 23:23:23

标签: android parse-platform

我正在制作一个新应用程序,此应用程序的一个功能是用户只能与他的手机联系人进行交互(与WhatsApp相同的概念)。

我使用Parse.com作为我的应用程序的后端,用户首先使用他们的电话号码注册,然后我应该比较所有用户在后端的联系人和联系人,以便仅检索通信联系人(然后在SQL中存储)

那么你有什么想法如何使这个功能更好,或者更好的想法进行比较?它消耗了很多带宽这个功能

 public void sync_contacts(){

        String phoneNo;
        ContentResolver cr = getContentResolver();
        Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
                null, null, null, null);
        if (cur.getCount() > 0) {
            while (cur.moveToNext()) {
                String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
                String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                if (Integer.parseInt(cur.getString(
                        cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
                    Cursor pCur = cr.query(
                            ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                            null,
                            ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
                            new String[]{id}, null);
                    while (pCur.moveToNext()) {

                        phoneNo = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                        phoneNo =  phoneNo.replace(" ", "");
                        phoneNo = phoneNo.replace("+33","0");
                        Log.d(name, phoneNo);
                        ParseQuery query = ParseUser.getQuery();
                        query.whereEqualTo("username",phoneNo);
                        query.getFirstInBackground(new GetCallback<ParseObject>() {
                            @Override
                            public void done(ParseObject parseObject, ParseException e) {
                                if (e == null ){
                                    contacts c = new contacts();
                                    if (!(parseObject.get("Name").toString()==null))    c.setName(parseObject.get("Name").toString());
                                    if (!(parseObject.get("username").toString()==null)) c.setNumero(parseObject.get("username").toString());
                                    ParseFile image = (ParseFile)parseObject.get("Profilepic");
                                    if(!(image==null))
                                    {
                                        c.setProfil(image.getUrl());
                                    }
                                    c.setShow("true");
                                    s.addcontact(c);
                                 Log.d("Found","IO");
                                }
                                else {
                                    Log.d("NotFound","IO");
                                }
                            }
                        });


                    }

                    pCur.close();
                }
            }


        }

    }

0 个答案:

没有答案