Pro Android with Kotlin


Download 5.42 Mb.
Pdf ko'rish
bet147/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   143   144   145   146   147   148   149   150   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile

171
CHAPTER 8: APIs
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_searchable)
// This is the standard way a system search dialog
// or the search widget communicates the query
// string:
if (Intent.ACTION_SEARCH == intent.action) {
val query =
intent.getStringExtra(SearchManager.QUERY)
// Add it to the recents suggestion database
val suggestions = SearchRecentSuggestions(this,
RecentsProvider.AUTHORITY, RecentsProvider.MODE)
suggestions.saveRecentQuery(q, null)
doMySearch(query)
}
// More initialization if necessary...
}
The second parameter for the saveRecentQuery() method could be a second line for 
annotation purposes. For this to work, you have to use val MODE = DATABASE_MODE_QUERIES 
or DATABASE_MODE_2LINES in the RecentsProvider and find a way to retrieve annotation text 
inside the SearchableActivity class.
Custom Suggestions
Custom suggestions are more powerful compared to recents suggestions. They can be fully 
app or domain specific, and you can provide intelligent suggestions to the user, tailored 
for the current user action. Compared to recents suggestions, you instead implement and 
register a ContentProvider by obeying certain rules.

The Android OS will fire ContentProvider.query(uri, projection, 
selection, selectionArgs, sortOrder calls with URIs like the following:
content://your.authority/
optional.suggest.path/
SUGGEST_URI_PATH_QUERY/

Here, your.authority is the content provider authority, /optional.
suggest.path might be added by the search configuration for 
disambiguation, and SUGGEST_URI_PATH_QUERY is the value of the 
constant SearchManager.SUGGEST_URI_PATH_QUERY. The  contains 
the string to be searched for. Both the selection and selectionArgs 
parameters will be filled only if appropriately configured in the search 
configuration.



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   143   144   145   146   147   148   149   150   ...   223




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling