2012-09-18 12 views
8

Sto provando a utilizzare ACTION_VOICE_SEARCH_HANDS_FREE in Android 4.1.Come posso utilizzare ACTION_VOICE_SEARCH_HANDS_FREE in Android 4.1?

Io uso questo modo:

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

funziona benissimo con ACTION_RECOGNIZE_SPEECH ma con ACTION_VOICE_SEARCH_HANDS_FREE mi ha questo:

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

Come posso usare ACTION_VOICE_SEARCH_HANDS_FREE?

+0

@ Rai220: che cos'è RECORD_CODE? – Shiv

risposta

0

È necessario installare sul dispositivo un'applicazione che contiene un'attività che risponde all'intento ACTION_VOICE_SEARCH_HANDS_FREE. Quindi la domanda diventa: quali app supportano questo intento? L'unica risposta che conosco è quella banale, "implementa te stesso una simile app", quindi sono anche interessato a questa domanda, ma non sono sicuro che si adatti al formato Stackoverflow.

1

@Kaarel risposto correttamente, ma per fornire un po 'più di informazioni:

Un'attività ha bisogno di registrare il seguente nel manifesto:

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

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

Google Search è registrato per questo intento, ma sarà solo reagire ad esso quando lo schermo è acceso e non chiuso: vedi sotto preso da 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(); 
      } 
     } 

Questa caratteristica è piuttosto ridondante attualmente due to this linked bug, in cui le applicazioni di sistema annullano la priorità, impedendo all'utente di scegliere un'alternativa installata.

Che quando hai creato tale applicazione e gli utenti non possono farne uso, è davvero molto fastidioso ............. anzi.

Problemi correlati