文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>[Android] Contacts

[Android] Contacts

时间:2010-08-06  来源:web_surf

  1. Read Contacts after sdk 2.0
    Refer to:
    http://www.higherpass.com/Android/Tutorials/Working-With-Android-Contacts/
    http://stackoverflow.com/questions/1721279/how-to-read-contacts-on-android-2-0
    Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, 
    null, null, null, null);
    while (cursor.moveToNext()) {
    String contactId = cursor.getString(cursor.getColumnIndex(
    ContactsContract.Contacts._ID));
    String hasPhone = cursor.getString(cursor.getColumnIndex(
    ContactsContract.Contacts.HAS_PHONE_NUMBER));
    if (Boolean.parseBoolean(hasPhone)) {
    // You know have the number so now query it like this
    Cursor phones = getContentResolver().query(
    ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
    null,
    ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId,
    null, null);
    /*
    Or
    Cursor phones = getContentResolver().query(
    ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
    null,
    ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
    new String[]{contactId
    }, null);
    */
    while (phones.moveToNext()) {
  2.      String phoneNumber = phones.getString( 
    phones
    .getColumnIndex(
    ContactsContract.CommonDataKinds.Phone.NUMBER));
    }
    phones
    .close();
    }
    Cursor emails = getContentResolver().query(
    ContactsContract.CommonDataKinds.Email.CONTENT_URI,
    null,
    ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = " + contactId,
    null, null);
    while (emails.moveToNext()) {
    // This would allow you get several email addresses
    String emailAddress = emails.getString(
    emails
    .getColumnIndex(
    ContactsContract.CommonDataKinds.CommonDataColumns.DATA));
    }
    emails
    .close();
    }
    cursor
    .close();

  3. xxx
相关阅读 更多 +
排行榜 更多 +
涂色我贼强安卓版

涂色我贼强安卓版

休闲益智 下载
脑细胞太牛了手机版

脑细胞太牛了手机版

休闲益智 下载
球球的冒险旅途

球球的冒险旅途

休闲益智 下载