RecognizerResultsIntent.java revision 41b14e8ff7a1774fc69dfcf1261f87e50dd55a03
1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.speech;
18
19import java.util.ArrayList;
20
21/**
22 * Constants for intents related to showing speech recognition results.
23 *
24 * These constants should not be needed for normal utilization of speech recognition. They
25 * would only be called if you wanted to trigger a view of voice search results in your
26 * application, or implemented if you wanted to offer a different view for voice search results
27 * with your application.
28 *
29 * The standard behavior here for someone receiving an {@link #ACTION_VOICE_SEARCH_RESULTS} is to
30 * first retrieve the list of {@link #EXTRA_VOICE_SEARCH_RESULT_STRINGS}, and use any provided
31 * HTML for that result in {@link #EXTRA_VOICE_SEARCH_RESULT_HTML}, if available, to display
32 * the search results. If that is not available, then the corresponding url for that result in
33 * {@link #EXTRA_VOICE_SEARCH_RESULT_URLS} should be used. And if even that is not available,
34 * then a search url should be constructed from the actual recognition result string.
35 *
36 * @hide for making public in a later release
37 */
38public class RecognizerResultsIntent {
39    private RecognizerResultsIntent() {
40        // Not for instantiating.
41    }
42
43    /**
44     * Intent that can be sent by implementations of voice search to display the results of
45     * a search in, for example, a web browser.
46     *
47     * This intent should always be accompanied by at least
48     * {@link #EXTRA_VOICE_SEARCH_RESULT_STRINGS}, and optionally but recommended,
49     * {@link #EXTRA_VOICE_SEARCH_RESULT_URLS}, and sometimes
50     * {@link #EXTRA_VOICE_SEARCH_RESULT_HTML}. These are three parallel arrays, where a
51     * recognition result string at index N of {@link #EXTRA_VOICE_SEARCH_RESULT_STRINGS} should
52     * be accompanied by a url to use for searching based on that string at index N of
53     * {@link #EXTRA_VOICE_SEARCH_RESULT_URLS}, and, possibly, the full html to display for
54     * that result at index N of {@link #EXTRA_VOICE_SEARCH_RESULT_HTML}.
55     *
56     * @hide for making public in a later release
57     */
58    public static final String ACTION_VOICE_SEARCH_RESULTS =
59            "android.speech.action.VOICE_SEARCH_RESULTS";
60
61    /**
62     * The key to an extra {@link ArrayList} of {@link String}s that contains the list of
63     * recognition alternates from voice search, in order from highest to lowest confidence.
64     *
65     * @hide for making public in a later release
66     */
67    public static final String EXTRA_VOICE_SEARCH_RESULT_STRINGS =
68            "android.speech.extras.VOICE_SEARCH_RESULT_STRINGS";
69
70    /**
71     * The key to an extra {@link ArrayList} of {@link String}s that contains the search urls
72     * to use, if available, for the recognition alternates provided in
73     * {@link #EXTRA_VOICE_SEARCH_RESULT_STRINGS}. This list should always be the same size as the
74     * one provided in {@link #EXTRA_VOICE_SEARCH_RESULT_STRINGS} - if a result cannot provide a
75     * search url, that entry in this ArrayList should be <code>null</code>, and the implementor of
76     * {@link #ACTION_VOICE_SEARCH_RESULTS} should execute a search of its own choosing,
77     * based on the recognition result string.
78     *
79     * @hide for making public in a later release
80     */
81    public static final String EXTRA_VOICE_SEARCH_RESULT_URLS =
82            "android.speech.extras.VOICE_SEARCH_RESULT_URLS";
83
84    /**
85     * The key to an extra {@link ArrayList} of {@link String}s that contains the html content to
86     * use, if available, for the recognition alternates provided in
87     * {@link #EXTRA_VOICE_SEARCH_RESULT_STRINGS}. This list should always be the same size as the
88     * one provided in {@link #EXTRA_VOICE_SEARCH_RESULT_STRINGS} - if a result cannot provide
89     * html, that entry in this list should be <code>null</code>, and the implementor of
90     * {@link #ACTION_VOICE_SEARCH_RESULTS} should back off to the corresponding url provided in
91     * {@link #EXTRA_VOICE_SEARCH_RESULT_URLS}, if available, or else should execute a search of
92     * its own choosing, based on the recognition result string.
93     *
94     * Currently this html content should be expected in the form of an "inline:" uri for the
95     * Browser. In the future this may change to a "content://" uri or some other identifier.
96     * Anyone who reads this extra should confirm that a result is in fact an "inline:" uri and
97     * back off to the urls or strings gracefully if it is not, thus maintaining future backwards
98     * compatibility if this changes.
99     *
100     * @hide not to be exposed immediately as the implementation details may change
101     */
102    public static final String EXTRA_VOICE_SEARCH_RESULT_HTML =
103            "android.speech.extras.VOICE_SEARCH_RESULT_HTML";
104}
105