title: How to register a custom speech recognition service?
body: <p>I created a simple speech recognition service: for this purpose I created a subclass of <code>android.speech.RecognitionService</code> and I created an activity to start and stop this service.</p>
  
  <p>My custom speech recognition service trivially uses the default speech recognizer, because my goal is simply to understand how the <code>RecognitionService</code> and <code>RecognitionService.Callback</code> classes work.</p>
  
  <pre><code>public class SimpleVoiceService extends RecognitionService {
  
      private SpeechRecognizer m_EngineSR;
  
      @Override
      public void onCreate() {
          super.onCreate();
          Log.i("SimpleVoiceService", "Service started");
      }
  
      @Override
      public void onDestroy() {
          super.onDestroy();
          Log.i("SimpleVoiceService", "Service stopped");
      }
  
      @Override
      protected void onCancel(Callback listener) {
          m_EngineSR.cancel();
      }
  
      @Override
      protected void onStartListening(Intent recognizerIntent, Callback listener) {
          m_EngineSR.setRecognitionListener(new VoiceResultsListener(listener));
          m_EngineSR.startListening(recognizerIntent);
      }
  
      @Override
      protected void onStopListening(Callback listener) {
          m_EngineSR.stopListening();
      }
  
  
      /**
       * 
       */
      private class VoiceResultsListener implements RecognitionListener {
  
          private Callback m_UserSpecifiedListener;
  
          /**
           * 
           * @param userSpecifiedListener
           */
          public VoiceResultsListener(Callback userSpecifiedListener) {
              m_UserSpecifiedListener = userSpecifiedListener;
          }
  
          @Override
          public void onBeginningOfSpeech() {
              try {
                  m_UserSpecifiedListener.beginningOfSpeech();
              } catch (RemoteException e) {
                  e.printStackTrace();
              }
          }
  
          @Override
          public void onBufferReceived(byte[] buffer) {
              try {
                  m_UserSpecifiedListener.bufferReceived(buffer);
              } catch (RemoteException e) {
                  e.printStackTrace();
              }
          }
  
          @Override
          public void onEndOfSpeech() {
              try {
                  m_UserSpecifiedListener.endOfSpeech();
              } catch (RemoteException e) {
                  e.printStackTrace();
              }
          }
  
          @Override
          public void onError(int error) {
              try {
                  m_UserSpecifiedListener.error(error);
              } catch (RemoteException e) {
                  e.printStackTrace();
              }
          }
  
          @Override
          public void onEvent(int eventType, Bundle params) { ; }
  
          @Override
          public void onPartialResults(Bundle partialResults) {
              try {
                  m_UserSpecifiedListener.partialResults(partialResults);
              } catch (RemoteException e) {
                  e.printStackTrace();
              }
          }
  
          @Override
          public void onReadyForSpeech(Bundle params) {
              try {
                  m_UserSpecifiedListener.readyForSpeech(params);
              } catch (RemoteException e) {
                  e.printStackTrace();
              }
          }
  
          @Override
          public void onResults(Bundle results) {
              try {
                  m_UserSpecifiedListener.results(results);
              } catch (RemoteException e) {
                  e.printStackTrace();
              }
          }
  
          @Override
          public void onRmsChanged(float rmsdB) {
              try {
                  m_UserSpecifiedListener.rmsChanged(rmsdB);
              } catch (RemoteException e) {
                  e.printStackTrace();
              }
          }
      }
  
  }
  </code></pre>
  
  <p>I start and stop the service using the following activity.</p>
  
  <pre><code>public class VoiceServiceStarterActivity extends Activity {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          Button startButton = new Button(this);
          startButton.setText("Start the service");
          startButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) { startVoiceService(); }
          });
          Button stopButton = new Button(this);
          stopButton.setText("Stop the service");
          stopButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) { stopVoiceService(); }
          });
          LinearLayout layout = new LinearLayout(this);
          layout.setOrientation(LinearLayout.VERTICAL);
          layout.addView(startButton);
          layout.addView(stopButton);
          setContentView(layout);
      }
  
      private void startVoiceService() {
          startService(new Intent(this, SimpleVoiceService.class));
      }
  
      private void stopVoiceService() {
          stopService(new Intent(this, SimpleVoiceService.class));
      }
  }
  </code></pre>
  
  <p>Finally I declared my service on the <code>AndroidManifest.xml</code> (see VoiceRecognition sample within Android SDK folder).</p>
  
  <pre><code>&lt;service android:name="SimpleVoiceService"
           android:label="@string/service_name" &gt;
  
      &lt;intent-filter&gt;
          &lt;action android:name="android.speech.RecognitionService" /&gt;
          &lt;category android:name="android.intent.category.DEFAULT" /&gt;
      &lt;/intent-filter&gt;
  &lt;/service&gt;
  </code></pre>
  
  <p>Then I installed this application on an Android device and I start it:
   - when I start the service, it starts properly;
   - when I stop it, it stops properly.</p>
  
  <p>But if I launch the following code in a another activity, the <code>activities</code> <code>List</code> contains only an element, which is the default speech recognizer.</p>
  
  <pre><code>PackageManager pm = getPackageManager();
  List&lt;ResolveInfo&gt; activities = pm.queryIntentActivities(
              new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
  </code></pre>
  
  <p>Why is my speech recognizer not returned among those present in the system?</p>