Example usage for android.speech RecognizerIntent EXTRA_RESULTS

List of usage examples for android.speech RecognizerIntent EXTRA_RESULTS

Introduction

In this page you can find the example usage for android.speech RecognizerIntent EXTRA_RESULTS.

Prototype

String EXTRA_RESULTS

To view the source code for android.speech RecognizerIntent EXTRA_RESULTS.

Click Source Link

Document

An ArrayList<String> of the recognition results when performing #ACTION_RECOGNIZE_SPEECH .

Usage

From source file:com.arlib.floatingsearchview.FloatingSearchView.java

/**
 * Handles voice recognition activity return.
 *
 * <p>In order for voice rec to work, this must be called from
 * the client activity's onActivityResult()</p>
 *
 * @param requestCode  the code with which the voice recognition intent
 *                     was started./*from  w w  w.j a va  2  s.  c om*/
 * @param resultCode
 * @param data
 */
public void onHostActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == mVoiceRecRequestCode) {

        if (resultCode == Activity.RESULT_OK) {

            ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            if (!matches.isEmpty()) {

                String newQuery = matches.get(0);

                mSearchInput.requestFocus();

                mSearchInput.setText(newQuery);
                mSearchInput.setSelection(mSearchInput.getText().length());
            }
        }
    }
}

From source file:com.google.sample.cast.refplayer.Synchronization.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
        ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        if (matches.size() > 0) {
            Log.d(TAG, matches.get(0));//from   w ww  .  j a  v a2  s .  c  om
            //sendMessage(matches.get(0));
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:de.azapps.mirakel.main_activity.MainActivity.java

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    final boolean isOk = resultCode == Activity.RESULT_OK;
    Log.v(MainActivity.TAG, "Result:" + requestCode);
    switch (requestCode) {
    case RESULT_SPEECH_NAME:
        if (data != null) {
            final List<String> text = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            ((EditText) findViewById(R.id.edit_name)).setText(text.get(0));
        }/*  w ww.j  a v a2  s .c om*/
        break;
    case RESULT_SPEECH:
        if (data != null) {
            final List<String> text = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            ((EditText) getTasksFragment().getFragmentView().findViewById(R.id.tasks_new)).setText(text.get(0));
        }
        break;
    case RESULT_ADD_FILE:
        if (data != null) {
            Log.d(MainActivity.TAG, "taskname " + this.currentTask.getName());
            getTaskFragment().update(this.currentTask);
        }
        break;
    case RESULT_SETTINGS:
        forceRebuildLayout();
        if (!MirakelCommonPreferences.highlightSelected()
                && ((this.oldClickedList != null) || (this.oldClickedTask == null))) {
            clearAllHighlights();
        }
        if (this.darkTheme != MirakelCommonPreferences.isDark()) {
            finish();
            if (this.startIntent == null) {
                this.startIntent = new Intent(MainActivity.this, MainActivity.class);
                this.startIntent.setAction(DefinitionsHelper.SHOW_LISTS);
                Log.wtf(MainActivity.TAG, "startIntent is null by switching theme");
            }
            startActivity(this.startIntent);
        }
        if (MirakelCommonPreferences.isTablet()) {
            forceRebuildLayout();
        } else if (this.mViewPager != null) {
            loadMenu(this.mViewPager.getCurrentItem());
        }
        if (getTasksFragment() != null) {
            getTasksFragment().updateButtons();
        }
        if (getTaskFragment() != null) {
            getTaskFragment().update(this.currentTask);
        }
        return;
    case RESULT_CAMERA:
    case RESULT_ADD_PICTURE:
        if (isOk) {
            final Task task;
            if (requestCode == MainActivity.RESULT_ADD_PICTURE) {
                task = this.currentTask;
            } else {
                task = Semantic.createTask(MirakelCommonPreferences.getPhotoDefaultTitle(),
                        Optional.fromNullable(this.currentList), false, this);
                task.save();
                if (getTasksFragment() != null) {
                    getTasksFragment().getLoaderManager().restartLoader(0, null, getTasksFragment());
                }
            }
            task.addFile(this, this.fileUri);
            getTaskFragment().update(task);
        }
        break;
    default:
        Log.w(MainActivity.TAG, "unknown activity result");
        break;
    }
}

From source file:com.example.android.cardreader.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_OK && resultCode == RESULT_OK) {
        System.out.println("Going into results");
        ArrayList<String> thingsYouSaid = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        String result = thingsYouSaid.get(0);
        System.out.println("Android Heard: " + result);
    }/*from ww w .j  a v  a2 s  .  c om*/
}

From source file:com.android.dialer.DialtactsFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
        if (resultCode == getActivity().RESULT_OK) {
            final ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            if (matches.size() > 0) {
                final String match = matches.get(0);
                mVoiceSearchQuery = match;
            } else {
                Log.e(TAG, "Voice search - nothing heard");
            }//from w  ww . j  av a 2 s  .c om
        } else {
            Log.e(TAG, "Voice search failed");
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:radu.pidroid.Controller.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == SPEECH_RECOGNITION_REQUEST_CODE && intent != null) {
        ArrayList<String> predictions = intent.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        mRecogniser.recogniseExecuteCommand(predictions);
    } // if// ww w. j av  a 2  s.  co m

    super.onActivityResult(requestCode, resultCode, intent);
}

From source file:com.android.launcher3.Launcher.java

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    handleActivityResult(requestCode, resultCode, data);
    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onActivityResult(requestCode, resultCode, data);
    }/*from w  w  w  .ja va 2s.  c o m*/
    if (REQUEST_ENABLE == requestCode) {
        super.onActivityResult(requestCode, resultCode, data);
    }
    if (RECOGNIZER_REQ_CODE == requestCode) {
        if (resultCode == Activity.RESULT_OK && null != data) {
            String search = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS).get(0);
            startSearch(search, true, null, true);
        }
    }
}

From source file:org.numixproject.hermes.activity.ConversationActivity.java

/**
 * On activity result/*from   w  w w .j  ava  2s  .  c  o  m*/
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK) {
        // ignore other result codes
        return;
    }

    switch (requestCode) {
    case REQUEST_CODE_SPEECH:
        ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        if (matches.size() > 0) {
            input.setText(matches.get(0));
        }
        break;
    case REQUEST_CODE_JOIN:
        addRecentRoom(data.getExtras().getString("channel"));
        joinChannelBuffer = data.getExtras().getString("channel");
        final Handler handler2 = new Handler();
        handler2.postDelayed(new Runnable() {
            @Override
            public void run() {
                refreshActivity();
            }
        }, 100);
        break;
    case REQUEST_CODE_USERS:
        Intent intent = new Intent(this, UserActivity.class);
        intent.putExtra(Extra.USER, data.getStringExtra(Extra.USER));
        startActivityForResult(intent, REQUEST_CODE_USER);
        break;
    case REQUEST_CODE_NICK_COMPLETION:
        insertNickCompletion((AutoCompleteTextView) findViewById(R.id.input),
                data.getExtras().getString(Extra.USER));
        break;
    case REQUEST_CODE_USER:
        final int actionId = data.getExtras().getInt(Extra.ACTION);
        final String nickname = data.getExtras().getString(Extra.USER);
        final IRCConnection connection = binder.getService().getConnection(server.getId());
        final String conversation = server.getSelectedConversation();
        final Handler handler = new Handler();

        // XXX: Implement me - The action should be handled after onResume()
        //                     to catch the broadcasts... now we just wait a second
        // Yes .. that's very ugly - we need some kind of queue that is handled after onResume()

        new Thread() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    // Do nothing
                }

                String nicknameWithoutPrefix = nickname;

                while (nicknameWithoutPrefix.startsWith("@") || nicknameWithoutPrefix.startsWith("+")
                        || nicknameWithoutPrefix.startsWith(".") || nicknameWithoutPrefix.startsWith("%")) {
                    // Strip prefix(es) now
                    nicknameWithoutPrefix = nicknameWithoutPrefix.substring(1);
                }

                switch (actionId) {
                case User.ACTION_REPLY:
                    final String replyText = nicknameWithoutPrefix + ": ";
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            input.setText(replyText);
                            input.setSelection(replyText.length());
                        }
                    });
                    break;
                case User.ACTION_QUERY:
                    Conversation query = server.getConversation(nicknameWithoutPrefix);
                    if (query == null) {
                        // Open a query if there's none yet
                        query = new Query(nicknameWithoutPrefix);
                        query.setHistorySize(binder.getService().getSettings().getHistorySize());
                        server.addConversation(query);

                        Intent intent = Broadcast.createConversationIntent(Broadcast.CONVERSATION_NEW,
                                server.getId(), nicknameWithoutPrefix);
                        binder.getService().sendBroadcast(intent);
                    }
                    break;
                case User.ACTION_WHOIS:
                    connection.whois(conversation, nicknameWithoutPrefix);
                    break;
                case User.ACTION_OP:
                    connection.op(conversation, nicknameWithoutPrefix);
                    break;
                case User.ACTION_DEOP:
                    connection.deOp(conversation, nicknameWithoutPrefix);
                    break;
                case User.ACTION_VOICE:
                    connection.voice(conversation, nicknameWithoutPrefix);
                    break;
                case User.ACTION_DEVOICE:
                    connection.deVoice(conversation, nicknameWithoutPrefix);
                    break;
                case User.ACTION_KICK:
                    connection.kick(conversation, nicknameWithoutPrefix);
                    break;
                case User.ACTION_BAN:
                    connection.ban(conversation, nicknameWithoutPrefix + "!*@*");
                    break;
                }
            }
        }.start();

        break;
    }
}

From source file:com.eveningoutpost.dexdrip.Home.java

/**
 * Receiving speech input/*  w w  w  .  j  a v  a 2  s .co  m*/
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
    case REQ_CODE_SPEECH_INPUT: {

        /*              Intent intent = data; // DEEEBUGGGG
        if (intent != null)
        {
            final Bundle bundle = intent.getExtras();
                
                
            if ((bundle != null) && (true)) {
                for (String key : bundle.keySet()) {
                    Object value = bundle.get(key);
                    if (value != null) {
                        Log.d(TAG+" xdebug", String.format("%s %s (%s)", key,
                                value.toString(), value.getClass().getName()));
                    }
                }
            }
        }*/

        if (resultCode == RESULT_OK && null != data) {
            ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            voiceRecognitionText.setText(result.get(0));
            voiceRecognitionText.setVisibility(View.VISIBLE);
            last_speech_time = JoH.ts();
            naturalLanguageRecognition(result.get(0));
        }
        recognitionRunning = false;
        break;
    }

    case REQ_CODE_SPEECH_NOTE_INPUT: {

        if (resultCode == RESULT_OK && null != data) {
            ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            //voiceRecognitionText.setText(result.get(0));
            //voiceRecognitionText.setVisibility(View.VISIBLE);
            //last_speech_time = JoH.ts();
            //naturalLanguageRecognition(result.get(0));
            String treatment_text = result.get(0).trim();
            Log.d(TAG, "Got treatment note: " + treatment_text);
            voiceRecognitionText.setText(result.get(0));
            voiceRecognitionText.setVisibility(View.VISIBLE);
            Treatments.create_note(treatment_text, 0); // timestamp?
            if (dialog != null) {
                dialog.cancel();
                dialog = null;
            }
            Home.staticRefreshBGCharts();

        }
        recognitionRunning = false;
        break;
    }
    case NFCReaderX.REQ_CODE_NFC_TAG_FOUND: {
        if (NFCReaderX.useNFC()) {
            NFCReaderX nfcReader = new NFCReaderX();
            nfcReader.tagFound(this, data);
        }
    }

    }
}

From source file:com.android.mail.ui.AbstractActivityController.java

/**
 * The mail activity calls other activities for two specific reasons:
 * <ul>/*from w w w.  j a va 2 s. c  o m*/
 *     <li>To add an account. And receives the result {@link #ADD_ACCOUNT_REQUEST_CODE}</li>
 *     <li>To update the password on a current account. The result {@link
 *     #REAUTHENTICATE_REQUEST_CODE} is received.</li>
 * </ul>
 * @param requestCode
 * @param resultCode
 * @param data
 */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case ADD_ACCOUNT_REQUEST_CODE:
        // We were waiting for the user to create an account
        if (resultCode == Activity.RESULT_OK) {
            // restart the loader to get the updated list of accounts
            mActivity.getLoaderManager().initLoader(LOADER_ACCOUNT_CURSOR, Bundle.EMPTY, mAccountCallbacks);
        } else {
            // The user failed to create an account, just exit the app
            mActivity.finish();
        }
        break;
    case REAUTHENTICATE_REQUEST_CODE:
        if (resultCode == Activity.RESULT_OK) {
            // The user successfully authenticated, attempt to refresh the list
            final Uri refreshUri = mFolder != null ? mFolder.refreshUri : null;
            if (refreshUri != null) {
                startAsyncRefreshTask(refreshUri);
            }
        }
        break;
    case CHANGE_NAVIGATION_REQUEST_CODE:
        if (ViewMode.isSearchMode(mViewMode.getMode())) {
            mActivity.setResult(resultCode, data);
            mActivity.finish();
        } else if (resultCode == Activity.RESULT_OK && data != null) {
            // We have have received a result that indicates we need to navigate to a
            // different folder or account. This happens if someone navigates using the
            // drawer on the search results activity.
            final Folder folder = data.getParcelableExtra(EXTRA_FOLDER);
            final Account account = data.getParcelableExtra(EXTRA_ACCOUNT);
            if (folder != null) {
                onFolderSelected(folder);
                mViewMode.enterConversationListMode();
            } else if (account != null) {
                switchToDefaultInboxOrChangeAccount(account);
                mViewMode.enterConversationListMode();
            }
        }
        break;
    case VOICE_SEARCH_REQUEST_CODE:
        if (resultCode == Activity.RESULT_OK) {
            final ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            if (!matches.isEmpty()) {
                // not sure how dependable the API is, but it's all we have.
                // take the top choice.
                mSearchViewController.onSearchPerformed(matches.get(0));
            }
        }
        break;
    }
}