开发者

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.getStrin开发者_开发问答g(nameIndex);
            String number = cursor.getString(numberIndex);
            s.append(name+ ": " + number + "\n");
        } while (cursor.moveToNext());


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜