日期:2014-05-16 浏览次数:20435 次
private String getContacts(Object parameters) {
        JSONArray peopleJSON = new JSONArray();
        Cursor tempContactsCursor = AndroidBaseActivity.self
                .getContentResolver().query(Contacts.People.CONTENT_URI, null,
                        null, null, null);
        if (tempContactsCursor.moveToFirst()) {
            do {
                JSONObject jsonPeopleNumbers = new JSONObject();
                // 获得联系人的ID号
                int idColumn = tempContactsCursor
                        .getColumnIndex(Contacts.People._ID);
                int peopleNameIndex = tempContactsCursor
                        .getColumnIndex(Contacts.People.DISPLAY_NAME);
                int mobileNumberIndex = tempContactsCursor
                        .getColumnIndex(Contacts.Phones.NUMBER);
                String id = tempContactsCursor.getString(idColumn);
                String name = tempContactsCursor.getString(peopleNameIndex);
                try {
                    jsonPeopleNumbers.put("mobile", tempContactsCursor
                            .getString(mobileNumberIndex));
                    jsonPeopleNumbers.put("name", name);
                    jsonPeopleNumbers.put("id", id);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                peopleJSON.put(jsonPeopleNumbers);
            } while (tempContactsCursor.moveToNext());
            tempContactsCursor.close();
        }
        return peopleJSON.toString();
    }