Skip to content

Commit

Permalink
added hands-free intent parameter, might not work for all devices
Browse files Browse the repository at this point in the history
  • Loading branch information
gmilette committed Mar 21, 2013
1 parent 7f4b3bf commit 467ed71
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/res/values/pref_strings.xml
Expand Up @@ -15,6 +15,10 @@
<string name="pref_websearch_title">Web Search</string>
<string name="pref_websearch_default">false</string>

<string name="pref_handsfree">pref_handsfree</string>
<string name="pref_handsfree_title">Hands Free</string>
<string name="pref_handsfree_default">false</string>

<string name="pref_direct">pref_direct</string>
<string name="pref_direct_title">Use SpeechRecognizer</string>
<string name="pref_direct_default">false</string>
Expand Down
5 changes: 5 additions & 0 deletions app/res/xml/speech_preferences.xml
Expand Up @@ -34,6 +34,11 @@
android:key="@string/pref_websearch"
android:title="@string/pref_websearch_title" />

<CheckBoxPreference
android:defaultValue="@string/pref_handsfree_default"
android:key="@string/pref_handsfree"
android:title="@string/pref_handsfree_title" />

<CheckBoxPreference
android:defaultValue="@string/pref_direct_default"
android:key="@string/pref_direct"
Expand Down
12 changes: 11 additions & 1 deletion app/src/root/gast/playground/speech/SpeechRecognitionPlay.java
Expand Up @@ -514,6 +514,9 @@ private Intent readRecognizerIntentFromPreferences()

//web search handling
boolean isWebSearchAction = preferences.getBoolean(this, R.string.pref_websearch, R.string.pref_websearch_default);

boolean isHandsFreeAction = preferences.getBoolean(this, R.string.pref_handsfree, R.string.pref_handsfree_default);

if (isWebSearchAction)
{
intentToSend = RecognizerIntentFactory.getWebSearchRecognizeIntent();
Expand All @@ -525,7 +528,14 @@ private Intent readRecognizerIntentFromPreferences()
}
else
{
intentToSend = RecognizerIntentFactory.getBlankRecognizeIntent();
if (isHandsFreeAction && Build.VERSION.SDK_INT >= 16)
{
intentToSend = RecognizerIntentFactory.getHandsFreeRecognizeIntent();
}
else
{
intentToSend = RecognizerIntentFactory.getBlankRecognizeIntent();
}
}

//language model
Expand Down
6 changes: 6 additions & 0 deletions library/src/root/gast/speech/RecognizerIntentFactory.java
Expand Up @@ -49,6 +49,12 @@ public static Intent getWebSearchRecognizeIntent()
return intent;
}

public static Intent getHandsFreeRecognizeIntent()
{
Intent intent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
return intent;
}

public static Intent getPossilbeWebSearchRecognizeIntent(String prompt)
{
Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Expand Down

0 comments on commit 467ed71

Please sign in to comment.