Get Skype name from Contacts list

↘锁芯ラ 提交于 2021-02-08 10:08:45

问题


I'm getting skype contacts in my android device with this code:

private void getContactList() {
    Cursor c = getContentResolver().query(
            RawContacts.CONTENT_URI,
            new String[] { RawContacts.CONTACT_ID,
                    RawContacts.DISPLAY_NAME_PRIMARY,
                    RawContacts.DISPLAY_NAME_ALTERNATIVE },
            RawContacts.ACCOUNT_TYPE + "= ?",
            new String[] { "com.skype.contacts.sync" }, null);

    int contactNameColumn = c
            .getColumnIndex(RawContacts.DISPLAY_NAME_ALTERNATIVE);
    int count = c.getCount();
    skypeName = new String[count];
    for (int i = 0; i < count; i++) {
        c.moveToPosition(i);
        skypeName[i] = c.getString(contactNameColumn);

        Log.i("KEY", skypeName[i]);
    }
}

This code works fine, but it returns the skype display names.However is there any possibility to get Skype name not the display name so I can call or video call using that Skype name?. Thanks, Regards.


回答1:


You need to query over the Data table not RawContacts, the Data table's data is organized by mimetypes, you just need to find the mimetype containing the info you're looking for, in skype's case it's: "vnd.android.cursor.item/com.skype.android.skypecall.action"

private void getContactList() {
    Cursor c = getContentResolver().query(
            Data.CONTENT_URI,
            new String[] { Data.CONTACT_ID, Data.DATA1 },
            Data.MIMETYPE + "= ?", 
            new String[] { "vnd.android.cursor.item/com.skype.android.skypecall.action" },
            null);

    while (c != null && c.moveToNext()) {
        String contact = c.getLong(0);
        String skype = c.getString(1);

        Log.i("contact " + contact + " has skype username: " + skype);
    }
}
  • I've typed the code here, so it's not checked and I might have typos
  • Make sure you ALWAYS close cursors via c.close()



回答2:


I'm not incredibly familiar with the Android-Skype API, but it looks like this line

.getColumnIndex(RawContacts.DISPLAY_NAME_ALTERNATIVE);

is what pulls the display name instead of the username. You could check the API and see if there's another RawContacts.method that fetches the username instead.

Additional information could be available here:

http://www.programmableweb.com/api/skype

or

http://www.skype.com/en/developer/



来源:https://stackoverflow.com/questions/32630395/get-skype-name-from-contacts-list

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!