How to get skype info from the android contact list

Newbie to using the Contacts Contract Content Provider.

I'm trying to make a skype call from within my application, and I can't figure out how to get the skype info from the android contacts. I am running a query through a ContentResolver to get all of the data for the contacts, but I don't know how to find the skype name within the data.


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.


如果您只想获取Skype联系人姓名和用户名列表,那么这可能会有所帮助

 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!

链接地址: http://www.djcxy.com/p/8760.html

上一篇: ActiveRecord自定义类型命名方案

下一篇: 如何从android联系人列表中获取skype信息