【问题标题】:Android- Fetch the contacts based on contact id greater than some valueAndroid-根据大于某个值的联系人ID获取联系人
【发布时间】:2013-10-10 06:03:48
【问题描述】:

我想定期从 android 获取联系人。为此我 想要这样的东西。我正在从 android并将其存储在我的本地数据库中。所以我将存储最后一个联系人 ID。 所以下次在病房里,如果添加了任何联系人,我需要得到那些 仅用于此目的的联系人,我想获取联系人ID 大于上次获取的联系人 ID。如何编写查询 内容解析器来获取联系人之类的东西。

Select * from tablename where id > 100;

【问题讨论】:

    标签: android android-contentprovider android-contacts


    【解决方案1】:
    Cursor  cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
                            null, // this will be the columns selection               
                            ContactsContract.Contacts._ID + ">100", // this is where you add the "where" part of the query, id is 1 in this case
                            null, // where args, you are skipping these               
                            null); // sort order
            if (cursor.getCount() > 0) {
                 while (cursor.moveToNext()) {
                    long id = Long.parseLong(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)));   
                    String displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)).trim();
    
                 }
            }
    

    希望这能解决您的问题

    【讨论】:

    • @DArO 对不起,我忘了在这里提及。那里的 Contact_ID 列类型是字符串。如果我与包含最后一个联系人 ID 的字符串变量进行比较,它不会给出这样的列异常。
    • ContactsContract.Contacts._ID 的值为“_id”,它是每个内容提供者表中 id 列的名称(根据规范)。因此,您在该特定部分中进行的查询是“where”之后的内容,在上面的情况下是 where _id > 100
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-21
    • 2013-12-16
    • 2011-11-13
    • 1970-01-01
    相关资源
    最近更新 更多