How to get Skype info from the Android contact list?
Asked Answered
M

3

7

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.

Meldon answered 30/7, 2011 at 23:8 Comment(1)
How about some advice on which uri to use to look for this information?Meldon
C
3

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.

Chipper answered 20/7, 2012 at 12:51 Comment(4)
hello i want to get contact from my skype account in android app. please help me.Surveillance
@Surveillance do you got the answer that fetch Skype contacts list in android is possible or not? I am also looking for the same.Defiant
@Akanksha in my case,its not possible...so i have to neglate this thing.Surveillance
This is not a solution or even a work around. ContactID is an integer value and primary key of the table, how on earth are you going to retrieve that?Supercilious
S
0

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]);
        }
    }
Swing answered 20/4, 2016 at 9:8 Comment(0)
S
0

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!

Supercilious answered 14/8, 2016 at 13:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.