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 17 package android.speech; 18 19 import android.os.Bundle; 20 21 import java.util.ArrayList; 22 23 /** 24 * Constants for intents related to showing speech recognition results. 25 * 26 * These constants should not be needed for normal utilization of speech recognition. They 27 * would only be called if you wanted to trigger a view of voice search results in your 28 * application, or implemented if you wanted to offer a different view for voice search results 29 * with your application. 30 * 31 * The standard behavior here for someone receiving an {@link #ACTION_VOICE_SEARCH_RESULTS} is to 32 * first retrieve the list of {@link #EXTRA_VOICE_SEARCH_RESULT_STRINGS}, and use any provided 33 * HTML for that result in {@link #EXTRA_VOICE_SEARCH_RESULT_HTML}, if available, to display 34 * the search results. If that is not available, then the corresponding url for that result in 35 * {@link #EXTRA_VOICE_SEARCH_RESULT_URLS} should be used. And if even that is not available, 36 * then a search url should be constructed from the actual recognition result string. 37 */ 38 public class RecognizerResultsIntent { 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} and 51 * {@link #EXTRA_VOICE_SEARCH_RESULT_HTML_BASE_URLS}. 52 * 53 * These are parallel arrays, where a recognition result string at index N of 54 * {@link #EXTRA_VOICE_SEARCH_RESULT_STRINGS} should be accompanied by a url to use for 55 * searching based on that string at index N of {@link #EXTRA_VOICE_SEARCH_RESULT_URLS}, 56 * and, possibly, the full html to display for that result at index N of 57 * {@link #EXTRA_VOICE_SEARCH_RESULT_HTML}. If full html is provided, a base url (or 58 * list of base urls) should be provided with {@link #EXTRA_VOICE_SEARCH_RESULT_HTML_BASE_URLS}. 59 */ 60 public static final String ACTION_VOICE_SEARCH_RESULTS = 61 "android.speech.action.VOICE_SEARCH_RESULTS"; 62 63 /** 64 * The key to an extra {@link ArrayList} of {@link String}s that contains the list of 65 * recognition alternates from voice search, in order from highest to lowest confidence. 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 public static final String EXTRA_VOICE_SEARCH_RESULT_URLS = 80 "android.speech.extras.VOICE_SEARCH_RESULT_URLS"; 81 82 /** 83 * The key to an extra {@link ArrayList} of {@link String}s that contains the html content to 84 * use, if available, for the recognition alternates provided in 85 * {@link #EXTRA_VOICE_SEARCH_RESULT_STRINGS}. This list should always be the same size as the 86 * one provided in {@link #EXTRA_VOICE_SEARCH_RESULT_STRINGS} - if a result cannot provide 87 * html, that entry in this list should be <code>null</code>, and the implementor of 88 * {@link #ACTION_VOICE_SEARCH_RESULTS} should back off to the corresponding url provided in 89 * {@link #EXTRA_VOICE_SEARCH_RESULT_URLS}, if available, or else should execute a search of 90 * its own choosing, based on the recognition result string. 91 * 92 * Currently this html content should be expected in the form of a uri with scheme 93 * {@link #URI_SCHEME_INLINE} for the Browser. In the future this may change to a "content://" 94 * uri or some other identifier. Anyone who reads this extra should confirm that a result is 95 * in fact an "inline:" uri and back off to the urls or strings gracefully if it is not, thus 96 * maintaining future backwards compatibility if this changes. 97 */ 98 public static final String EXTRA_VOICE_SEARCH_RESULT_HTML = 99 "android.speech.extras.VOICE_SEARCH_RESULT_HTML"; 100 101 /** 102 * The key to an extra {@link ArrayList} of {@link String}s that contains the base url to 103 * assume when interpreting html provided in {@link #EXTRA_VOICE_SEARCH_RESULT_HTML}. 104 * 105 * A list of size 1 may be provided to apply the same base url to all html results. 106 * A list of the same size as {@link #EXTRA_VOICE_SEARCH_RESULT_STRINGS} may be provided 107 * to apply different base urls to each different html result in the 108 * {@link #EXTRA_VOICE_SEARCH_RESULT_HTML} list. 109 */ 110 public static final String EXTRA_VOICE_SEARCH_RESULT_HTML_BASE_URLS = 111 "android.speech.extras.VOICE_SEARCH_RESULT_HTML_BASE_URLS"; 112 113 /** 114 * The key to an extra {@link ArrayList} of {@link Bundle}s that contains key/value pairs. 115 * All the values and the keys are {@link String}s. Each key/value pair represents an extra HTTP 116 * header. The keys can't be the standard HTTP headers as they are set by the WebView. 117 * 118 * A list of size 1 may be provided to apply the same HTTP headers to all web results. A 119 * list of the same size as {@link #EXTRA_VOICE_SEARCH_RESULT_STRINGS} may be provided to 120 * apply different HTTP headers to each different web result in the list. These headers will 121 * only be used in the case that the url for a particular web result (from 122 * {@link #EXTRA_VOICE_SEARCH_RESULT_URLS}) is loaded. 123 */ 124 public static final String EXTRA_VOICE_SEARCH_RESULT_HTTP_HEADERS = 125 "android.speech.extras.EXTRA_VOICE_SEARCH_RESULT_HTTP_HEADERS"; 126 127 /** 128 * The scheme used currently for html content in {@link #EXTRA_VOICE_SEARCH_RESULT_HTML}. 129 * Note that this should only be used in tandem with this particular extra; it should 130 * NOT be used for generic URIs such as those found in the data field of an Intent. 131 */ 132 public static final String URI_SCHEME_INLINE = "inline"; 133 } 134