Пример #1
0
		/// <summary>
		/// Create and return an Intent that can launch the voice search activity, perform a specific
		/// voice transcription, and forward the results to the searchable activity.
		/// </summary>
		/// <remarks>
		/// Create and return an Intent that can launch the voice search activity, perform a specific
		/// voice transcription, and forward the results to the searchable activity.
		/// </remarks>
		/// <param name="baseIntent">The voice app search intent to start from</param>
		/// <returns>A completely-configured intent ready to send to the voice search activity
		/// 	</returns>
		private android.content.Intent createVoiceAppSearchIntent(android.content.Intent 
			baseIntent, android.app.SearchableInfo searchable)
		{
			android.content.ComponentName searchActivity = searchable.getSearchActivity();
			// create the necessary intent to set up a search-and-forward operation
			// in the voice search system.   We have to keep the bundle separate,
			// because it becomes immutable once it enters the PendingIntent
			android.content.Intent queryIntent = new android.content.Intent(android.content.Intent
				.ACTION_SEARCH);
			queryIntent.setComponent(searchActivity);
			android.app.PendingIntent pending = android.app.PendingIntent.getActivity(getContext
				(), 0, queryIntent, android.app.PendingIntent.FLAG_ONE_SHOT);
			// Now set up the bundle that will be inserted into the pending intent
			// when it's time to do the search.  We always build it here (even if empty)
			// because the voice search activity will always need to insert "QUERY" into
			// it anyway.
			android.os.Bundle queryExtras = new android.os.Bundle();
			// Now build the intent to launch the voice search.  Add all necessary
			// extras to launch the voice recognizer, and then all the necessary extras
			// to forward the results to the searchable activity
			android.content.Intent voiceIntent = new android.content.Intent(baseIntent);
			// Add all of the configuration options supplied by the searchable's metadata
			string languageModel = android.speech.RecognizerIntent.LANGUAGE_MODEL_FREE_FORM;
			string prompt = null;
			string language = null;
			int maxResults = 1;
			android.content.res.Resources resources = getResources();
			if (searchable.getVoiceLanguageModeId() != 0)
			{
				languageModel = resources.getString(searchable.getVoiceLanguageModeId());
			}
			if (searchable.getVoicePromptTextId() != 0)
			{
				prompt = resources.getString(searchable.getVoicePromptTextId());
			}
			if (searchable.getVoiceLanguageId() != 0)
			{
				language = resources.getString(searchable.getVoiceLanguageId());
			}
			if (searchable.getVoiceMaxResults() != 0)
			{
				maxResults = searchable.getVoiceMaxResults();
			}
			voiceIntent.putExtra(android.speech.RecognizerIntent.EXTRA_LANGUAGE_MODEL, languageModel
				);
			voiceIntent.putExtra(android.speech.RecognizerIntent.EXTRA_PROMPT, prompt);
			voiceIntent.putExtra(android.speech.RecognizerIntent.EXTRA_LANGUAGE, language);
			voiceIntent.putExtra(android.speech.RecognizerIntent.EXTRA_MAX_RESULTS, maxResults
				);
			voiceIntent.putExtra(android.speech.RecognizerIntent.EXTRA_CALLING_PACKAGE, searchActivity
				 == null ? null : searchActivity.flattenToShortString());
			// Add the values that configure forwarding the results
			voiceIntent.putExtra(android.speech.RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT, 
				pending);
			voiceIntent.putExtra(android.speech.RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT_BUNDLE
				, queryExtras);
			return voiceIntent;
		}
Пример #2
0
		/// <summary>Create and return an Intent that can launch the voice search activity for web search.
		/// 	</summary>
		/// <remarks>Create and return an Intent that can launch the voice search activity for web search.
		/// 	</remarks>
		private android.content.Intent createVoiceWebSearchIntent(android.content.Intent 
			baseIntent, android.app.SearchableInfo searchable)
		{
			android.content.Intent voiceIntent = new android.content.Intent(baseIntent);
			android.content.ComponentName searchActivity = searchable.getSearchActivity();
			voiceIntent.putExtra(android.speech.RecognizerIntent.EXTRA_CALLING_PACKAGE, searchActivity
				 == null ? null : searchActivity.flattenToShortString());
			return voiceIntent;
		}