今天讲使用intent打开搜索,包括特定app的上下文环境搜索和Web搜索。另外,再讲下使用intent打开相关的各种设置页面。
Search
Search using a specific app
To support search within the context of your app, declare an intent filter in your app with the SEARCH_ACTION action, as shown in the example intent filter below.
Action
"com.google.android.gms.actions.SEARCH_ACTION"
Support search queries from Google Voice Actions.
Extras
QUERY
A string that contains the search query.
Example intent filter:
<activity android:name=".SearchActivity">
<intent-filter>
<action android:name="com.google.android.gms.actions.SEARCH_ACTION"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
Perform a web search
To initiate a web search, use the ACTION_WEB_SEARCH action and specify the search string in the SearchManager.QUERY extra.
Action
ACTION_WEB_SEARCH
Data URI Scheme
None
MIME Type
None
Extras
SearchManager.QUERY
The search string.
Example intent:
public void searchWeb(String query) {
Intent intent = new Intent(Intent.ACTION_SEARCH);
intent.putExtra(SearchManager.QUERY, query);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}Settings
Open a specific section of Settings
To open a screen in the system settings when your app requires the user to change something, use one of the following intent actions to open the settings screen respective to the action name.
Action
ACTION_SETTINGS
ACTION_WIRELESS_SETTINGS
ACTION_AIRPLANE_MODE_SETTINGS
ACTION_WIFI_SETTINGS
ACTION_APN_SETTINGS
ACTION_BLUETOOTH_SETTINGS
ACTION_DATE_SETTINGS
ACTION_LOCALE_SETTINGS
ACTION_INPUT_METHOD_SETTINGS
ACTION_DISPLAY_SETTINGS
ACTION_SECURITY_SETTINGS
ACTION_LOCATION_SOURCE_SETTINGS
ACTION_INTERNAL_STORAGE_SETTINGS
ACTION_MEMORY_CARD_SETTINGS
See the Settings documentation for additional settings screens that are available.
Data URI Scheme
None
MIME Type
None
Example intent:
public void openWifiSettings() {
Intent intent = new Intent(Intent.ACTION_WIFI_SETTINGS);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
本文介绍了如何通过Intent实现应用内的上下文环境搜索和Web搜索,并展示了如何利用Intent打开Android系统的各种设置页面。
415

被折叠的 条评论
为什么被折叠?



