2012-09-18 27 views
8

Estoy tratando de usar ACTION_VOICE_SEARCH_HANDS_FREE en Android 4.1.¿Cómo puedo usar ACTION_VOICE_SEARCH_HANDS_FREE en Android 4.1?

utilizo esta manera:

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

funciona bien con ACTION_RECOGNIZE_SPEECH pero con ACTION_VOICE_SEARCH_HANDS_FREE que tiene esto:

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

¿Cómo puedo usar ACTION_VOICE_SEARCH_HANDS_FREE?

+0

@ Rai220: ¿Qué es RECORD_CODE? – Shiv

Respuesta

0

Necesita instalar en su dispositivo una aplicación que contenga una actividad que responda al intento ACTION_VOICE_SEARCH_HANDS_FREE. Entonces la pregunta es: ¿qué aplicaciones son compatibles con esta intención? La única respuesta que conozco es trivial, "implemente una aplicación usted mismo", por lo que también estoy interesado en esta pregunta, pero no estoy seguro de si se ajusta al formato Stackoverflow.

1

@Kaarel respondió correctamente, pero para el suministro de un poco más de información:

Una actividad debe registrarse lo siguiente en el manifiesto:

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

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

de búsqueda de Google se ha registrado para este propósito, pero lo hará Sólo reaccionar a ella cuando la pantalla está encendida y no bloqueado: véase más adelante tomada de AudioService

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(); 
      } 
     } 

Esta característica es bastante redundante actualmente due to this linked bug, donde las aplicaciones del sistema anulan la prioridad, lo que impide que el usuario elija una alternativa instalada.

Que cuando has creado una aplicación así y los usuarios no pueden hacer uso de ella, es realmente muy molesto ............. de hecho.