`
yangguangfu
  • 浏览: 1531736 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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();
    }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics