How to get skype information from android contact list

Beginner to use the Contact Content Provider.

I am trying to make a skype call from my application and I cannot figure out how to get skype information from Android contacts. I run a request through ContentResolver to get all the data for contacts, but I don’t know how to find the Skype name in the data.

+7
source share
3 answers

This works 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; } 

Go to contactID to use:

  String skypeID = getSkypeID(mContext, contactID); if(!skypeID.matches("noMatch") { //skypeID found // Skype intent here } 

Hope this helps.

+3
source

if you just want to get a list of contact names and skype username this might 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]); } } 
0
source

Please see the code below. (working from my application)

 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 makeSkypeCall is called (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!

0
source

All Articles