我有一个 ContentProvider
和一个 DataBase,其中有两列,分别名为 "_id"
和 “_name”
。首先,我从 ContactsContract.CommonDataKinds.Phone
复制 id 和 name。然后我需要更改 ContentProvider
中的数据。然后我需要从 ContactsContract.CommonDataKinds.Phone
再次访问 id
和 name
但基于现在位于我的 **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/