Vivek Warde
Vivek Warde

Reputation: 1504

Storing user contacts in parse.com

I am fetching user contacts & trying to store it in parse.com Dashboard by using this code

public void readContacts(){
         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))) ==1) {
                    System.out.println(name );
                    testObject.put("names", name);

                    // get the phone number
                    Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,
                                           ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
                                           new String[]{id}, null);
                    while (pCur.moveToNext()) {
                          String phone = pCur.getString(
                                 pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                         System.out.println( phone);
                        testObject.put("phonenumber", phone);

                    }
                    pCur.close();
                    testObject.saveInBackground();
    }
   }
  }
 }

I am successful to print these contacts in logcat.

But When I see it in parse.com dashboard(Data Browser) it is only adding one row , & when I click refresh each time I see other contact replaced in that row.

I want to store 1 contact in 1 row which I am unable to achieve.

Can anyone tell what is being wrong ?

Thanks in advance !

Upvotes: 0

Views: 150

Answers (1)

Vivek Warde
Vivek Warde

Reputation: 1504

I solved it my own, & posting the answer of my own question for helping future readers !

In my case ParseObject testObject = new ParseObject("Contacts"); was declared globally !

And for storing each contact there should be different a object each time So I added the above line just before testObject.put("names", name);

Upvotes: 1

Related Questions