androidskype

Get Skype name from Contacts list


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.


Solution

  • 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);
        }
    }