android developer tiny share-20160830

本文介绍了如何通过Intent实现应用内的上下文环境搜索和Web搜索,并展示了如何利用Intent打开Android系统的各种设置页面。

今天讲使用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);
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值