Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中使用Contacts contract.Contacts.CONTACT\u LAST\u UPDATED\u时间戳?_Android_Contacts - Fatal编程技术网

如何在android中使用Contacts contract.Contacts.CONTACT\u LAST\u UPDATED\u时间戳?

如何在android中使用Contacts contract.Contacts.CONTACT\u LAST\u UPDATED\u时间戳?,android,contacts,Android,Contacts,我正在讨论如何在android中使用Contacts contract.Contacts.CONTACT\u LAST\u UPDATED\u时间戳 下面是我显示IllegalStateException的代码 Cursor allContacts = this.getContentResolver().query( ContactsContract.RawContacts.CONTENT_URI, null, null, null, null); St

我正在讨论如何在android中使用Contacts contract.Contacts.CONTACT\u LAST\u UPDATED\u时间戳

下面是我显示IllegalStateException的代码

    Cursor allContacts = this.getContentResolver().query(
            ContactsContract.RawContacts.CONTENT_URI, null, null, null, null);

    StringBuilder sbCurrentVersion = new StringBuilder();
    allContacts.moveToFirst();

    for (int i = 0; i < allContacts.getCount(); i++) {
        String id = allContacts.getString(allContacts.getColumnIndex(ContactsContract.Contacts._ID));
        String name = allContacts.getString(allContacts.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
        String col = allContacts.getString(allContacts.getColumnIndex(ContactsContract.Contacts.CONTACT_LAST_UPDATED_TIMESTAMP));
        sbCurrentVersion.append("  "+id+":"+name+" : "+col);
        allContacts.moveToNext();
    }

         It shows following IllegalStateException
                                                                 java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
                                                                                    at android.database.CursorWindow.nativeGetString(Native Method)
                                                                                    at android.database.CursorWindow.getString(CursorWindow.java:438)
                                                                                    at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
                                                                                    at android.database.CursorWrapper.getString(CursorWrapper.java:137)
                                                                                    at com.example.dj.contentobserverdemo.ContentObserverService.sGetCurrentContatcsVersions(ContentObserverService.java:111)
                                                                                    at com.example.dj.contentobserverdemo.ContentObserverService.access$000(ContentObserverService.java:23)
                                                                                    at com.example.dj.contentobserverdemo.ContentObserverService$MyContentObserver.onChange(ContentObserverService.java:83)
                                                                                    at android.database.ContentObserver.onChange(ContentObserver.java:130)
                                                                                    at android.database.ContentObserver.onChange(ContentObserver.java:145)
                                                                                    at android.database.ContentObserver$NotificationRunnable.run(ContentObserver.java:216)
                                                                                    at android.os.Handler.handleCallback(Handler.java:739)
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                    at android.os.Looper.loop(Looper.java:148)
                                                                                    at android.os.HandlerThread.run(HandlerThread.java:61)
Cursor allContacts=this.getContentResolver().query(
ContactsContract.RawContacts.CONTENT(URI,null,null,null,null);
StringBuilder sbCurrentVersion=新的StringBuilder();
allContacts.moveToFirst();
对于(int i=0;i
我得到了为什么它显示非法状态异常的答案。使用ContactsContacts.Contacts.CONTENT\u URI代替ContactsContacts.RawContacts.CONTENT\u URI获取所有联系人

Cursor allContacts = this.getContentResolver().query(
        ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

StringBuilder sbCurrentVersion = new StringBuilder();
allContacts.moveToFirst();

for (int i = 0; i < allContacts.getCount(); i++) {
    String id = allContacts.getString(allContacts.getColumnIndex(ContactsContract.Contacts._ID));
    String name = allContacts.getString(allContacts.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
    String col = allContacts.getString(allContacts.getColumnIndex(ContactsContract.Contacts.CONTACT_LAST_UPDATED_TIMESTAMP));
    sbCurrentVersion.append("  "+id+":"+name+" : "+col);
    allContacts.moveToNext();
}
Cursor allContacts=this.getContentResolver().query(
Contacts contract.Contacts.CONTENT_URI,null,null,null,null);
StringBuilder sbCurrentVersion=新的StringBuilder();
allContacts.moveToFirst();
对于(int i=0;i
我得到了为什么它显示非法状态异常的答案。使用ContactsContacts.Contacts.CONTENT\u URI代替ContactsContacts.RawContacts.CONTENT\u URI获取所有联系人

Cursor allContacts = this.getContentResolver().query(
        ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

StringBuilder sbCurrentVersion = new StringBuilder();
allContacts.moveToFirst();

for (int i = 0; i < allContacts.getCount(); i++) {
    String id = allContacts.getString(allContacts.getColumnIndex(ContactsContract.Contacts._ID));
    String name = allContacts.getString(allContacts.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
    String col = allContacts.getString(allContacts.getColumnIndex(ContactsContract.Contacts.CONTACT_LAST_UPDATED_TIMESTAMP));
    sbCurrentVersion.append("  "+id+":"+name+" : "+col);
    allContacts.moveToNext();
}
Cursor allContacts=this.getContentResolver().query(
Contacts contract.Contacts.CONTENT_URI,null,null,null,null);
StringBuilder sbCurrentVersion=新的StringBuilder();
allContacts.moveToFirst();
对于(int i=0;i
发布stacktrace,然后使用
getColumnIndex
而不是
getColumnIndexOrThrow
,您将知道是什么错误,它显示“contact\u last\u updated\u timestamp”列不存在。”。。那么我怎样才能得到上次更新的时间??。文档说明这是获取API 18中引入的更新时间戳的方法。您是否为联系人添加了读取权限您将错误的
Uri
传递到
query()
方法发布堆栈跟踪,而不是
getColumnIndex
使用
getColumnIndexOrThrow
,您将知道它显示了什么错误“列‘contact_last_updated_timestamp’不存在。”…那么如何获取上次更新的时间???。文档说明这是获取更新的时间戳的方法,该方法在中介绍