【问题标题】:How to get Skype info from the Android contact list?如何从 Android 联系人列表中获取 Skype 信息?
【发布时间】:2011-07-30 23:08:26
【问题描述】:

新手使用联系人合同内容提供者。

我正在尝试从我的应用程序中拨打 Skype 电话,但我不知道如何从 Android 联系人中获取 Skype 信息。我正在通过 ContentResolver 运行查询以获取联系人的所有数据,但我不知道如何在数据中找到 Skype 名称。

【问题讨论】:

  • 关于使用哪个 uri 查找此信息的建议如何?

标签: android skype


【解决方案1】:

这对我有用:

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

传入使用的contactID:

    String skypeID = getSkypeID(mContext, contactID);

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

    // Skype intent here

    }

希望对您有所帮助。

【讨论】:

  • 您好,我想在 Android 应用中通过我的 Skype 帐户取得联系。请帮帮我。
  • @dipali 您是否得到了在 android 中获取 Skype 联系人列表是否可行的答案?我也在找一样的。
  • @Akanksha 在我的情况下,这是不可能的......所以我必须否定这件事。
  • 这不是解决方案,甚至不是解决方法。 ContactID 是一个整数值和表的主键,你到底要如何检索它?
【解决方案2】:

如果您只想获取 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]);
        }
    }

【讨论】:

    【解决方案3】:

    请参考以下代码。 (在我的应用中工作)

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

    您只需调用 String username = getSkypeUsername(context, "name_of_person_to_call")。使用这个用户名调用 ma​​keSkypeCall(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);
    }
    

    如果这有帮助,请告诉我!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-21
      • 2012-10-23
      • 2012-02-21
      • 2016-10-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多