android 获取手机SIM卡联系人

最近做到一个获取联系人的应用。一开始只是做获取联系人,后来需求需要做获取手机联系人和获取SIM卡联系人。其实原理都一样,都是去查询。只不过数据库的位置不一样。这里获取手机联系人的方法我就不写了。我直接写上获取手机SIM卡中得联系人的方法。

/**
     * 获取SIM卡中联系人
     *
     * @author sy
     * @return ArrayList<ContactsModel>
     */
     @SuppressWarnings("deprecation")
     public ArrayList<ContactsModel> getContactFromSim()
     {
     contactsModels.clear();
     // contactsModels = new ArrayList<ContactsModel>();
     Uri uri = Uri.parse("content://icc/adn");
     Cursor cursor = Contacts.this.getContentResolver().query(uri, null, null,
     null, null);
     while (cursor.moveToNext())
     {
     ContactsModel contactsModel = new ContactsModel();
     String id = cursor.getString(cursor.getColumnIndex(People._ID));
     String name = cursor.getString(cursor.getColumnIndex(People.NAME));
     String phoneNumber =
     cursor.getString(cursor.getColumnIndex(People.NUMBER));
     contactsModel.setContactId(id);
     contactsModel.setContactName(name);
     contactsModel.setContactPhone(phoneNumber);
     contactsModels.add(contactsModel);
     }
     return contactsModels;
     }

 

"content://icc/adn" 其实就是我们SIM卡中存放联系人的位置

ArrayList<ContactModel> 这个大家应该都明白,其实就是一个ArrayList里面存放了我的联系人的Model实体类,至于实体类里的变量,大家自己去定义吧。我就不贴了。反正就是姓名啊,地址啊,手机号码啊之类的,根绝大家的需求吧。

posted @ 2012-08-07 15:42  大胸弟、  阅读(449)  评论(0编辑  收藏  举报