In order to implement search with assistance from the Android system (to deliver search queriesto an activity and provide search suggestions), your application must provide a search configurationin the form of an XML file.
This page describes the search configuration file in terms of its syntax and usage. For moreinformation about how to implement search features for your application, begin with the developerguide about Creating a Search Interface.
res/xml/filename.xml
Android uses the filename as the resource ID.
<searchable>
attributes:
android:label
android:label
attribute of your <activity>
or<application>
manifest element. This label is only visible to the user when you setandroid:includeInGlobalSearch
to 'true', in which case, this label is used to identifyyour application as a searchable item in the system's search settings.android:hint
android:hint
as 'Search <content-or-product>'. For example,'Search songs and artists' or 'Search YouTube'.android:searchMode
Value | Description |
---|---|
'queryRewriteFromText' | Use the value from the SUGGEST_COLUMN_TEXT_1 column to rewrite the query text. |
'queryRewriteFromData' | Use the value from the SUGGEST_COLUMN_INTENT_DATA column to rewrite thequery text. This should only be used when the values in SUGGEST_COLUMN_INTENT_DATA are suitable for userinspection and editing, typically HTTP URI's. |
For more information, see the discussion about rewriting the query text in Adding Custom Suggestions.
android:searchButtonText
android:inputType
inputType
for a list of suitable values for thisattribute.android:imeOptions
imeOptions
for a list of suitable valuesfor this attribute. Search suggestion attributes
If you have defined a content provider to generate search suggestions, you need to define additional attributes that configure communications with the content provider. When providing search suggestions, you need some of the following
<searchable>
attributes:android:searchSuggestAuthority
- String. (Required to provide search suggestions.) This value must match the authority string provided in the
android:authorities
attribute of the Android manifest<provider>
element. android:searchSuggestPath
- String. This path is used as a portion of the suggestions query
Uri
, after the prefix and authority, but beforethe standard suggestions path. This is only required if you have a single content provider issuing different types of suggestions (such as for different data types) and you need a way to disambiguate the suggestions queries when you receive them. android:searchSuggestSelection
- String. This value is passed into your query function as the
selection
parameter. Typically this is a WHERE clausefor your database, and should contain a single question mark, which is a placeholder for theactual query string that has been typed by the user (for example,'query=?'
). However, youcan also use any non-null value to trigger the delivery of the query text via theselectionArgs
parameter (and then ignore theselection
parameter). android:searchSuggestIntentAction
- String. The default intent action to be used when a user clicks on a custom search suggestion (such as
'android.intent.action.VIEW'
). If this is not overridden by the selected suggestion (via theSUGGEST_COLUMN_INTENT_ACTION
column), this value is placed in the actionfield of theIntent
when the user clicks a suggestion. android:searchSuggestIntentData
- String. The default intent data to be used when a user clicks on a custom search suggestion. If not overridden by the selected suggestion (via the
SUGGEST_COLUMN_INTENT_DATA
column), this value is placed in the data field of theIntent
when the user clicks a suggestion. android:searchSuggestThreshold
- Integer. The minimum number of characters needed to trigger a suggestion look-up. Only guarantees that the system will not query your content provider for anything shorter than the threshold. The default value is 0.
For more information about the above attributes for search suggestions, see the guides for Adding Recent Query Suggestions and Adding Custom Suggestions.
Quick Search Box attributes
To make your custom search suggestions available to Quick Search Box, you need some of the following
<searchable>
attributes:android:includeInGlobalSearch
- Boolean. (Required to provide search suggestions in Quick Search Box.) Set to 'true' if you want your suggestions to be included in the globally accessible Quick Search Box. The user must still enable your application as a searchable item in the system search settings before your suggestions will appear in Quick Search Box.
android:searchSettingsDescription
- String. Provides a brief description of the search suggestions that you provideto Quick Search Box, which is displayed in the searchable items entry for your application.Your description should concisely describe the content that is searchable. For example, 'Artists,albums, and tracks' for a music application, or 'Saved notes' for a notepad application.
android:queryAfterZeroResults
- Boolean. Set to 'true' if you want your content provider to be invoked for supersets of queries that have returned zero results in the past. For example, ifyour content provider returned zero results for 'bo', it should be requiried for 'bob'. If set to'false', supersets are ignored for a single session ('bob' does not invoke a requery). This lastsonly for the life of the search dialog or the life of the activity when using the search widget(when the search dialog or activity is reopened, 'bo' queries yourcontent provider again). The default value is false.
Voice search attributes
To enable voice search, you'll need some of the following
<searchable>
attributes:android:voiceSearchMode
Value | Description |
---|---|
'showVoiceSearchButton' | Display a voice search button, if voice search is available on the device. If set,then either 'launchWebSearch' or 'launchRecognizer' must also be set (separated by the pipe | character). |
'launchWebSearch' | The voice search button takes the user directly to a built-in voice web search activity. Most applications don't need this flag, as it takes the user away from the activity in which search was invoked. |
'launchRecognizer' | The voice search button takes the user directly to a built-in voice recording activity. This activity prompts the user to speak, transcribes the spoken text, and forwards the resulting query text to the searchable activity, just as if the user typed it into the search UI and clicked the search button. |
android:voiceLanguageModel
Value | Description |
---|---|
'free_form' | Use free-form speech recognition for dictating queries. This is primarilyoptimized for English. This is the default. |
'web_search' | Use web-search-term recognition for shorter, search-like phrases. This isavailable in more languages than 'free_form'. |
Also see
EXTRA_LANGUAGE_MODEL
for more information.android:voicePromptText
android:voiceLanguage
Locale
(such as 'de'
for German or 'fr'
forFrench). This is needed only if it is different from the current value of Locale.getDefault()
.android:voiceMaxResults
ACTION_SEARCH
intent's primary query. Must be 1 or greater. Use EXTRA_RESULTS
toget the results from the intent. If not provided, the recognizer chooses how many results to return.<actionkey>
Not all action keys are available on every device, and notall keys are allowed to be overridden in this way. For example, the 'Home' key cannot be used andmust always return to the home screen. Also be sure not to define an actionkey for a key that's needed for typing a search query. This essentially limits theavailable and reasonable action keys to the call button and menu button. Also note that actionkeys are not generally discoverable, so you should not provide them as a core user feature.
You must define the
android:keycode
to define the key and at least one of theother three attributes in order to define the search action.Blood and Gore, Intense Violence, Sexual Themes, Strong Language, Use of Drugs and Alcohol, Online Interactions Not Rated by the ESRB. Publisher:Ubisoft. Upon your arrival, you must spark the fires of resistance to liberate the community. Far cry 5 download for pc.
Menentukan Tata Bahasa Regular Dari String En
attributes:
android:keycode
KeyEvent
that represents the action key you wish to respond to (for example 'KEYCODE_CALL'
). This is added to the ACTION_SEARCH
intent that is passed to your searchable activity. To examine the key code, use getIntExtra(SearchManager.ACTION_KEY)
. Not allkeys are supported for a search action, as many of them are used for typing, navigation, or systemfunctions.android:queryActionMsg
ACTION_SEARCH
intent that the system passes to your searchable activity. To examine the string, use getStringExtra(SearchManager.ACTION_MSG)
.android:suggestActionMsg
getStringExtra(SearchManager.ACTION_MSG)
. This should only be used if all yoursuggestions support this action key. If not all suggestions can handle the same action key, thenyou must instead use the following android:suggestActionMsgColumn
attribute.android:suggestActionMsgColumn
android:suggestActionMsg
attribute to define the action message for all suggestions, each entry inyour content provider provides its own action message. First, you must define a column in yourcontent provider for each suggestion to provide an action message, then provide the name of thatcolumn in this attribute. The system looks at your suggestion cursor, using the string provided here to select your action message column, and then select the action message string from the Cursor. That string is added to the intent that the system passes to your searchable activity (using the action you'vedefined for suggestions). To examine the string, use
getStringExtra(SearchManager.ACTION_MSG)
. If the datadoes not exist for the selected suggestion, the action key is ignored.res/xml/searchable.xml
:Espresso-Intents is an extension to Espresso, which enables validation andstubbing of intents sent out by theapplication under test. It’s like Mockito, but for Android Intents.
If your app delegates functionality to other apps or the platform, you can useEspresso-Intents to focus on your own app's logic while assuming that other appsor the platform will function correctly. With Espresso-Intents, you can matchand validate your outgoing intents or even provide stub responses in place ofactual intent responses.
Include Espresso-Intents in your project
In your app's
app/build.gradle
file, add the following line insidedependencies
:Espresso-Intents is only compatible with Espresso 2.1+ and version 0.3+ ofAndroid testing libraries, so make sure you update those lines as well:
Write test rules
Before writing an Espresso-Intents test, set up an
IntentsTestRule
. This is anextension of the class ActivityTestRule
and makes it easy to useEspresso-Intents APIs in functional UI tests. An IntentsTestRule
initializesEspresso-Intents before each test annotated with @Test
and releasesEspresso-Intents after each test run.The following code snippet is an example of an
IntentsTestRule
:Match
Espresso-Intents provides the ability to intercept outgoing intents based oncertain matching criteria, which are defined using Hamcrest Matchers. Hamcrestallows you to:
- Use an existing intent matcher: Easiest option, which should almost alwaysbe preferred.
- Implement your own intent matcher: Most flexible option. More details areavailable in the section entitled 'Writing custom matchers' within theHamcrest tutorial.
Espresso-Intents offers the
intended()
and intending()
methods for intent validation andstubbing, respectively. Both take a Hamcrest Matcher<Intent>
object as anargument.The following code snippet shows intent validation that uses existing intentmatchers that matches an outgoing intent that starts a browser:
Validate intents
Espresso-Intents records all intents that attempt to launch activities from theapplication under test. Using the
intended()
method, which is similar toMockito.verify()
, you can assert that a given intent has been seen. However,Espresso-Intents doesn't stub out responses to intents unless you explicitly configureit to do so.The following code snippet is an example test that validates, but doesn't stubout responses to, an outgoing intent that launches an external 'phone' activity:
Stubbing
Using the
intending()
method, which is similar to Mockito.when()
, you canprovide a stub response for activities that are launched withstartActivityForResult()
. This is particularly useful for external activitiesbecause you cannot manipulate the user interface of an external activity norcontrol the ActivityResult
returned to the activity under test.The following code snippets implement an example
activityResult_DisplaysContactsPhoneNumber()
test, which verifies that when auser launches a 'contact' activity in the app under test, the contact phonenumber is displayed:- Build the result to return when a particular activity is launched. Theexample test intercepts all Intents sent to 'contacts' and stubs out theirresponses with a valid
ActivityResult
, using the result codeRESULT_OK
- Instruct Espresso to provide the stub result object in response to allinvocations of the 'contacts' intent:
- Verify that the action used to launch the activity produces the expectedstub result. In this case, the example test checks that the phone number'123-345-6789' is returned anddisplayed when the 'contacts activity' is launched:
Here is the complete
activityResult_DisplaysContactsPhoneNumber()
test:Additional resources
For more information about using Espresso-Intents in Android tests, consultthe following resources.
Samples
- IntentsBasicSample:Basic usage of
intended()
andintending()
. - IntentsAdvancedSample:Simulates a user fetching a bitmap using the camera.