2013-03-19 75 views
1

使用此代碼,我能夠清除在谷歌Play商店中的應用程序最近查詢:谷歌Play商店中的應用程序最近查詢

SearchRecentSuggestions query = new SearchRecentSuggestions(this, "com.google.android.finsky.RecentSuggestionsProvider", 1);  
query.clearHistory(); 

但是,我怎麼能使用最新的查詢? (例如:顯示TextView中的第一個查詢)

+0

如何修復SecurityException? java.lang.SecurityException:權限拒絕:打開提供程序com.google.android.finsky.providers.RecentSuggestionsProvider – Proverbio 2015-01-22 08:06:15

回答

0

默認情況下,將查詢作爲uri參數(Uri對象)的最後一個段添加。要在這種情況下檢索查詢文本,只需使用getLastPathSegment()。例如:

String query = uri.getLastPathSegment()。toLowerCase();

例如,這裏是你會如何形成的android:searchSuggestSelection屬性來創建一個全文檢索語句:

`

<?xml version="1.0" encoding="utf-8"?> 
<searchable xmlns:android="http://schemas.android.com/apk/res/android" 
    android:label="@string/app_label" 
    android:hint="@string/search_hint" 
    android:searchSuggestAuthority="com.example.MyCustomSuggestionProvider" 
    android:searchSuggestIntentAction="android.intent.action.VIEW" 
    android:searchSuggestSelection="word MATCH ?"> 
</searchable> 

` 有了這個配置,您的查詢()方法提供選擇參數爲「詞匹配?」和selectionArgs參數作爲搜索查詢。當你將這些傳遞給一個SQLite query()方法作爲它們各自的參數時,它們被合成在一起(問號被替換爲查詢文本)。如果您選擇以這種方式接收建議查詢,並且需要向查詢文本添加通配符,請將它們附加(和/或前綴)到selectionArgs參數,因爲此值使用引號括起來並插入問號標記的位置。

上述示例中的另一個新屬性是android:searchSuggestIntentAction,它定義了當用戶選擇建議時隨每個意向發送的意向操作。有關聲明建議意圖的部分將對此進行進一步討論。

+0

如何以這種方式訪問​​查詢? – monte 2013-03-19 06:57:34

+0

'//獲取意圖,//驗證操作並獲取查詢Intent intent = getIntent(); (Intent.ACTION_SEARCH.equals(intent.getAction())){String query = intent.getStringExtra(SearchManager.QUERY); doMySearch(查詢); }' – 2013-03-19 07:05:30

+0

我無法理解這個想法。我想要的不是清除查詢,我怎樣才能使用它的數據。就像列出它們或將它們放入textview中一樣。 – monte 2013-03-19 09:00:33

相關問題