android - 如何仅从带有电话号码的谷歌联系人(而不是 facebook 等)中选择联系人?

标签 android

我需要修复我的旧应用程序中的错误。错误的一部分是我如何选择联系人。这是我需要的:

  1. 联系人必须来自 “正常”谷歌联系人列表,即 我不想获得任何联系人 来自 Facebook 或类似网站。
  2. 联系人必须至少有一个电话号码。
  3. 联系人必须来自旧的 android.provider.Contacts 提供商。
  4. 如果我可以使用 Intent 来获取联系人 URI 而无需自己创建选择列表等,那就太好了。

听起来很简单,但我真的很挣扎。这就是我正在尝试的:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = new Intent(Intent.ACTION_PICK, Contacts.People.CONTENT_URI);
    startActivityForResult(intent, PICK_CONTACT_REQUEST);
}

可以正常工作。我仍然看到没有电话号码的联系人,但我可以接受。更糟糕的是,我仍然在列表中看到 facebook 联系人!这似乎与在 Froyo API for the deprecated Contacts content provider 中找到的以下引用相矛盾:

The APIs have been superseded by ContactsContract. The newer APIs allow access multiple accounts and support aggregation of similar contacts. These APIs continue to work but will only return data for the first Google account created, which matches the original behavior.

这听起来正是我想要的,但遗憾的是,这不是我得到的。

最后,这是我的具体问题,希望有人能回答:

  1. 为什么我在使用 android.provider.Contacts 内容提供程序时会看到 Facebook 联系人?
  2. 如果这不起作用,我还能如何让用户选择带有电话号码的 Google 联系人?

非常感谢。 古斯塔夫

最佳答案

我有一个类似的问题,这至少给你联系电话号码(包括 facebook)...

Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(intent, PICK_CONTACT_REQUEST);

关于android - 如何仅从带有电话号码的谷歌联系人(而不是 facebook 等)中选择联系人?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3797743/

相关文章:

android - XML 解析器无连接错误

android - 如何在不恢复中间 fragment 的情况下清除 Android fragment 返回堆栈

android - PreferenceActivity 未在 Android 上显示两次

android - 使用 weakReference 和 WakHasMap Android 位图

android - 每个产品 flavor 多个 google-services.json

android - 当您在按钮上移动时如何检测触摸

android - 在现有的 android 调用应用程序中添加一个额外的按钮?

android - 如何为我的自定义导航配置 list 文件(任务相关性?)

android - 我如何将 HashMap 转换为数组?

android - 使用 AccountManager 处理登录和记住我