android - 如何在 Android 中加入(字面意思)两个/多个内容提供商?

标签 android android-contentprovider android-contentresolver

我有一个 ContentProvider 和一个 DataBase,其中有两列,分别名为 "_id"“_name”。首先,我从 ContactsContract.CommonDataKinds.Phone 复制 idname。然后我需要更改 ContentProvider 中的数据。然后我需要从 ContactsContract.CommonDataKinds.Phone 再次访问 idname但基于现在位于我的 **ContentProvider** 中的那些 id (s)。

我知道如何在两个表中使用Join。但不知道如何使用 ContentProviders 来做到这一点。

最佳答案

我将这样做:

Cursor locals = // Get from my local ContentProvider
Cursor distant = // Get from distant phone ContentProvider
List<String> names = new ArrayList<>();
CursorJoiner joiner = new CursorJoiner(locals, new String[] {"_id"}, distant, new String[] {"_id"});
for (CursorJointer.Result joinerResult : joiner) {
    switch (joinerResult) {
    case BOTH:
        String name = distant.getString(distant.getColumnIndex("name"));
        names.add(name);
        break;
    }
}

names 包含您的姓名列表。

关于android - 如何在 Android 中加入(字面意思)两个/多个内容提供商?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24615420/

相关文章:

javascript - 如何在 android phonegap 中将 Json 对象从 js 传递到 java?

android - 任何人都可以向我描述一下 android 的 aidl 中的 oneway 是什么吗?

android - 使用最新数据动态刷新 RecyclerView

android - 我无法更新联系人的备注部分

android - 如何以编程方式从 Android 获取 whatsapp 联系人?

android - 在 Android 4.0.3 上流式传输 m3u8 播放列表

android尝试套接字路由错误

android - 在 Android Q 上使用 Glide 显示来自具有 "content://"方案的 URI 的图像

android - 在 Android Studio 上构建非常非常慢的 Gradle

android - 如何获取所有联系人的名字,姓氏,电子邮件,电话号码等而不重复