search

Home  >  Q&A  >  body text

android - 小米 vivo 如何实现读取通讯录?

普通数据库读取不可行,小米vivo管理允许读取通讯录后依旧不可行,其他品牌手机可以读取,求助可行读取办法,在线等。

黄舟黄舟2830 days ago927

reply all(4)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 17:10:26

    Using the Uri provided by ContentResolver and ContentProvider, you can obtain the address book in the system
    Management contact Uri: ContactsContract.Conacts.CONTENT_URI
    Phone Uri: ContactsContract.CommonDataKinds.Phone.CONTENT_URI

    Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null,null,null,null);
    //遍历结果
    if (cursor.moveToNext()){
    //联系人ID
    String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
    //联系人名字
    String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
    ....
    } 
        

    Finally, pay attention to adding permissions.

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 17:10:26

    The answer above is correct, don’t forget to turn off cursor at the end

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 17:10:26

    If you use ContentProvider, it will be the same for every platform. Mobile phone manufacturers cannot change it casually because the mobile phone will go through the CTS process before it is launched. So if it doesn't work on your side, it's probably because there's something wrong with the code.

    reply
    0
  • PHPz

    PHPz2017-04-17 17:10:26

    Xiaomi and vivo are not the same brand. We can read Xiaomi's address book, but we don't have a vivo test machine. Are you referring to Xiaomi vivo being unable to read?

    reply
    0
  • Cancelreply