我试图通过以下代码从Android浏览器中获取我的搜索值:
public void getBrowserHist() {
String[] mColumnStrings =
{ Browser.SearchColumns._ID,
Browser.SearchColumns.SEARCH,
Browser.SearchColumns.DATE
};
Cursor mCur = getContentResolver().query(Browser.SEARCHES_URI,
mColumnStrings, Browser.SearchColumns.SEARCH, null, null);
int url = mCur.getColumnIndex(Browser.SearchColumns.SEARCH);
Log.d(DEBUG_TAG, "Bookmarks count: " + mCur.getCount());
mCur.moveToFirst();
while (!mCur.isAfterLast()) {
Log.v("titleIdx", mCur.getString(url));
mCur.moveToNext();
}
}
问题是搜索结果为空。 mcur.getCount()方法返回0,我现在不知道为什么。有没有人有任何建议?
答案 0 :(得分:1)
Cursor cursor = this.context.getContentResolver().query(Browser.SEARCHES_URI, null, null, null, null);
if (cursor.moveToFirst()) {
while (!cursor.isAfterLast()) {
final int indexDate = cursor.getColumnIndex(Browser.SearchColumns.DATE);
final int indexTerm = cursor.getColumnIndex(Browser.SearchColumns.SEARCH);
String date = cursor.getString(indexDate);
String term = cursor.getString(indexTerm);
cursor.moveToNext();
}
}
cursor.close();