5

How to hide Voice search icon in android firetv extends android.support.v17.leanback.app.SearchFragment library. its coming default in my code when i extended that search library... For now i dont want to use voice search functionality...

Below listener is coming default :::

 setSpeechRecognitionCallback(new SpeechRecognitionCallback() {
            @Override
            public void recognizeSpeech() {
                Log.v(TAG, "recognizeSpeech");
                try {
                    Intent mSpeechRecognizerIntent = getRecognizerIntent();
                    mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, new Long(3000));
                    mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, new Long(2000));
                    startActivityForResult(mSpeechRecognizerIntent, REQUEST_SPEECH);
                    //startActivityForResult(getRecognizerIntent(), REQUEST_SPEECH);
                } catch (ActivityNotFoundException e) {
                    Log.e(TAG, "Cannot find activity for speech recognizer", e);
                }
            }
        });
vinoth48
  • 61
  • 4

3 Answers3

6

Here is how you can hide the voice search in searchFragment .

Inside the searchFragment you need to Override the onCreateView.

 @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = super.onCreateView(inflater, container, savedInstanceState);
    FrameLayout searchFrame = root.findViewById(R.id.lb_search_frame);
   SearchBar mSearchBar = searchFrame.findViewById(R.id.lb_search_bar);
   SpeechOrbView mSpeechOrbView = mSearchBar.findViewById(R.id.lb_search_bar_speech_orb);


    if (mSpeechOrbView != null) {
        mSpeechOrbView.setOrbIcon(ContextCompat.getDrawable(getActivity(),
                R.drawable.ic_search_sel));
        mSpeechOrbView.setVisibility(View.GONE);
    }return root;}

Do this it will work. Happy Coding :)

vallabh
  • 505
  • 6
  • 10
0

Based from this link, Google has default voice search. If you do not supply a callback via setSpeechRecognitionCallback(SpeechRecognitionCallback), an internal speech recognizer will be used for which your application will need to request android.permission.RECORD_AUDIO.

So you need to do either

  • Implement setSpeechRecognitionCallback
  • Request android.permission.RECORD_AUDIO on AndroidManifest.xml
abielita
  • 13,147
  • 2
  • 17
  • 59
0

Old question but finally added to the Leanback library:

Made speech recognizer optional for SearchSupportFragment

https://developer.android.com/jetpack/androidx/releases/leanback?hl=nb#1.1.0-rc01

kazhiu
  • 749
  • 9
  • 21