arun
arun

Reputation: 11

Retrieve contacts from Android Froyo 2.2

im using the following code segment to fetch contact names and numbers, it works fine on the emulator, but when i install the app in my Froyo 2.2.1, it just returns me the name, and instead of returning me the number it returns, 'null', can anyone help me solve this issue ? will greatly appreciate any solution. Thanks

  ContentResolver r = getContentResolver();
        Cursor cursor = r.query(People.CONTENT_URI, null, null, null, null);

        // Let activity manage the cursor
       // startManagingCursor(cursor);
     //   Log.d(TAG, "cursor.getCount()=" + cursor.getCount());

        // Get value from content provider
        int nameIndex = cursor.getColumnIndex(People.NAME);
        int numberIndex = cursor.getColumnIndex(People.NUMBER);//OrThrow(People.NUMBER);

        cursor.moveToFirst();
        StringBuilder s = new StringBuilder();
        do {
            String name = cursor.getString(nameIndex);
            String number = cursor.getString(numberIndex);
            s.append(name+ ": " + number + "\n");
        } while (cursor.moveToNext());

Upvotes: 1

Views: 652

Answers (1)

senola
senola

Reputation: 782

The People API is deprecated try using the ContactsContract API which was already introduced for android 2.0+.

You can look at this blog post about using the contactscontract or the api documentation

Upvotes: 2

Related Questions