Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Skype info from the Android contact list?

Tags:

android

skype

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.

like image 211
sanddune Avatar asked Jul 30 '11 23:07

sanddune


People also ask

Where are Skype Contacts stored?

With Skype, your contacts are stored centrally on our servers. You can access them anywhere, as long as you sign in with the same account and password in Skype.


1 Answers

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.

like image 97
brandall Avatar answered Oct 20 '22 05:10

brandall