2011-10-03 116 views
0

得到的搜索結果我想從Android瀏覽器中得到我的搜索值與下面的代碼:試圖從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,我現在不是爲什麼。有沒有人有任何建議?

回答

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();