How can I use ACTION_VOICE_SEARCH_HANDS_FREE in Android 4.1?

I am trying to use ACTION_VOICE_SEARCH_HANDS_FREE in Android 4.1 .

I am using this method:

 Intent intent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); intent.putExtra(RecognizerIntent.EXTRA_SECURE, true); startActivityForResult(intent, RECORD_CODE); 

It works fine with ACTION_RECOGNIZE_SPEECH , but with ACTION_VOICE_SEARCH_HANDS_FREE I have this:

 android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.speech.action.VOICE_SEARCH_HANDS_FREE (has extras) } 

How can I use ACTION_VOICE_SEARCH_HANDS_FREE ?

+8
android speech-recognition android-4.2-jelly-bean
source share
2 answers

@ Kaarel answered correctly, but to provide a little more information:

The following must be registered in the manifest:

  <intent-filter > <action android:name="android.speech.action.VOICE_SEARCH_HANDS_FREE" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> 

Google Search is registered for this purpose, but it will only respond to it when the screen is turned on and not locked: see AudioService below

 private void startVoiceBasedInteractions(boolean needWakeLock) { Intent voiceIntent = null; // select which type of search to launch: // - screen on and device unlocked: action is ACTION_WEB_SEARCH // - device locked or screen off: action is ACTION_VOICE_SEARCH_HANDS_FREE // with EXTRA_SECURE set to true if the device is securely locked PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); boolean isLocked = mKeyguardManager != null && mKeyguardManager.isKeyguardLocked(); if (!isLocked && pm.isScreenOn()) { voiceIntent = new Intent(android.speech.RecognizerIntent.ACTION_WEB_SEARCH); } else { voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, isLocked && mKeyguardManager.isKeyguardSecure()); } // start the search activity if (needWakeLock) { mMediaEventWakeLock.acquire(); } try { if (voiceIntent != null) { voiceIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); mContext.startActivity(voiceIntent); } } catch (ActivityNotFoundException e) { Log.w(TAG, "No activity for search: " + e); } finally { if (needWakeLock) { mMediaEventWakeLock.release(); } } 

This feature is pretty redundant at present due to this related error where system applications redefine priority, thereby preventing the user from choosing the installed alternative.

That when you created such an application and users cannot use it, it’s really very annoying ............. really.

+1
source share

You need to install an application on the device containing an action that meets the intent ACTION_VOICE_SEARCH_HANDS_FREE . Therefore, the question arises: what applications support this intention? The only answer I know is trivial, "implement such an application yourself," so this question interests me too, but I'm not sure if it matches the Stackoverflow format.

0
source share

All Articles