How to get skype info from the android contact list

不打扰是莪最后的温柔 提交于 2019-12-05 05:47:15

This is working for me:

    public String getSkypeID(Context mContext, String contactID) {
    Log.i("getContactNumber");

    String returnID = "noMatch";

    ContentResolver cr = mContext.getContentResolver();
    Cursor skype = cr.query(ContactsContract.Data.CONTENT_URI, null, ContactsContract.Data.CONTACT_ID
            + " = " + contactID, null, null);

    while (skype.moveToNext()) {

        int type = skype
                .getInt(skype
                        .getColumnIndex(ContactsContract.CommonDataKinds.Im.PROTOCOL));
        String imName = skype.getString(skype
                .getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA));

        switch (type) {
        case ContactsContract.CommonDataKinds.Im.PROTOCOL_SKYPE:
            Log.d("contactID: " + contactID + " type: " + type
                    + " imName: " + imName);

            returnID = imName;

            break;

        default:
            Log.v("Other numbers: " + imName);
            break;
        }

    }

    return returnID;
}

Pass in the contactID for usage:

    String skypeID = getSkypeID(mContext, contactID);

    if(!skypeID.matches("noMatch") {
    //skypeID found

    // Skype intent here

    }

Hope that helps.

if you just want to fetch list of skype contact names and username then this may help

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

        int contactNameColumn = c
                .getColumnIndex(ContactsContract.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]);
        }
    }

Please refer the below code. (working from my app)

public String getSkypeUsername(Context context, String name) {
    Cursor c = context.getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, ContactsContract.Contacts.Data.MIMETYPE + "=?",
            new String[] { "vnd.android.cursor.item/com.skype.android.skypecall.action" }, null);

    while (c != null && c.moveToNext()) {
        String primary = c.getString(c.getColumnIndex(ContactsContract.Data.DISPLAY_NAME_PRIMARY));
        String alternate = c.getString(c.getColumnIndex(ContactsContract.Data.DISPLAY_NAME_ALTERNATIVE));
        if(primary.equalsIgnoreCase(name) || alternate.equalsIgnoreCase(name)) {
            String username = c.getString(c.getColumnIndex(ContactsContract.Data.DATA1));
            c.close();
            return username;
        }
    }
    c.close();
    return null;
}

All you have to do is call String username = getSkypeUsername(context, "name_of_person_to_call"). With this username call makeSkypeCall(context, username)

public void makeSkypeCall(Context context, String username) {
        Intent sky = new Intent("android.intent.action.VIEW");
        sky.setData(Uri.parse("skype:" + username + "?call"));
        context.startActivity(sky);
}

Let me know if this helps!

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