/paw/src/com/google/marvin/paw/RecoInvokerActivity.java

http://eyes-free.googlecode.com/ · Java · 39 lines · 30 code · 7 blank · 2 comment · 2 complexity · 7815a460f3113c9a73d8f4d1730f841b MD5 · raw file

  1. package com.google.marvin.paw;
  2. import java.util.ArrayList;
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.speech.RecognizerIntent;
  6. import android.util.Log;
  7. import android.widget.Toast;
  8. public class RecoInvokerActivity extends Activity {
  9. @Override
  10. protected void onResume() {
  11. super.onResume();
  12. Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
  13. intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
  14. RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
  15. startActivityForResult(intent, 0);
  16. }
  17. @Override
  18. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  19. if (resultCode != Activity.RESULT_OK) {
  20. // Something went wrong, bail!
  21. finish();
  22. return;
  23. }
  24. ArrayList<String> results = data.getExtras().getStringArrayList(RecognizerIntent.EXTRA_RESULTS);
  25. // TODO: make this take the reco result
  26. Intent queryIntent = new Intent("com.google.marvin.paw.action.websearch");
  27. queryIntent.putExtra("query", results.get(0));
  28. sendBroadcast(queryIntent);
  29. Toast.makeText(this, "Processing: " + results.get(0), 1).show();
  30. finish();
  31. }
  32. }