我可以使用以下光标在Android 2.2上获取默认历史记录,其中CONTENT_URI指向Browser.BOOKMARKS_URI
cursor = context.getContentResolver().query(CONTENT_URI,
Browser.HISTORY_PROJECTION, null, null, null);
if (cursor.moveToLast())
String url = cursor.getString(Browser.HISTORY_PROJECTION_URL_INDEX);
但它在Android ICS上无效我得到了错误的网址并且它总是一样的:1970-01-01 00:00:00 http://www.samsung.com/m-manual/common
PS:获取我使用cursor.getLong(Browser.HISTORY_PROJECTION_DATE_INDEX)
答案 0 :(得分:0)
您是否也尝试了getAllBookmarks()?
Cursor cursor = Browser.getAllBookmarks(getContentResolver());
if (cursor != null) {
try {
while (cursor.moveToNext()) {
String url = cursor.getString(cursor.getColumnIndex(Browser.BookmarkColumns.URL));
}
} finally {
cursor.close();
}
}
编辑:
String sortOrder = Browser.BookmarkColumns.DATE + " ASC";
Cursor cursor = getContentResolver().query(CONTENT_URI, Browser.HISTORY_PROJECTION, null, null, sortOrder);
if (cursor != null) {
try {
if (cursor.moveToLast()) {
String url = cursor.getString(Browser.HISTORY_PROJECTION_URL_INDEX);
long date = cursor.getLong(Browser.HISTORY_PROJECTION_DATE_INDEX);
}
} finally {
cursor.close();
}
}
实际上为什么http://www.samsung.com/m-manual/common
网址错了?你期待什么网址?您尚未指定要排序的列。通过cursor.moveToLast()
,您将光标移动到最后一项,而不是遍历书签。