2013-05-17 104 views
0

我需要在我的应用程序中将手机联系人分成组,但仅限于我的应用程序,因此我不想将任何组添加到原始手机联系人数据库。我已将自己的数据库设置为拥有我的群组表格:Android应用程序联系人组

groups(group_id int, group_name text, message text) 

and contacts_group table。

contacts_group(contact_id, group_id) 

现在我面临的问题:我应该如何创建查询到从我的组(电话联系DATABSE)的所有联系人。

我需要这样的:Select ... DISPLAY_NAME,... NUMBER其中..._ID(String [] ids),而String [] ids是来自contacts_group表的contact_id数组。是否有可能把我的字符串数组'?'在原始查询? As .. Select ... where .._ ID in?,string []? 感谢您的帮助 Regards

回答

0

Probelm解决了。解决方案:

public static Cursor getContactsFromGroup(String[] ids, SQLiteDatabase db) { 
     Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; 
     String[] projection = { ContactsContract.CommonDataKinds.Phone._ID, 
       ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, 
       ContactsContract.CommonDataKinds.Phone.NUMBER }; 

     Cursor c = context.getContentResolver().query(uri, projection, 
       "_ID IN (" + makePlaceHolders(ids.length) + ")", ids, null); 


    } 

其中makePlacHoldes(int)将“?”字符,多达long是param数组。 Regards

相关问题