读书人

android1.5取得所有联系人ID人名默

发布时间: 2012-08-29 08:40:14 作者: rapoo

android1.5获得所有联系人ID,人名,默认移动电话号码,并生成 JSONArray数据

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();    }

读书人网 >JavaScript

热点推荐