question

adam355 avatar image
adam355 asked

Fire TV leanback app crashing after search fragment

Hello,

I am currently porting my Android TV app to the Fire TV and I am only having one issue. I understand that I cannot use the voice search on Android TV and that is probably why I am having problems. My app was built upon an old version of this library. https://github.com/googlesamples/androidtv-Leanback

When the android tv leanback search fragment loads I type in what I am looking for with the amazon keyboard and it works perfectly. The problem is after I select one of the search results it crashes on closing down the speech recognizer. Unfortunately the speech recognizer is closed in a parent class that I do not have access to in the leanback support library so cannot stop the searchfragment class from calling releaseRecognizer(); when it hits onPause();

Is there a way I can handle this so my app doesnt crash without having to create an entirely new search fragment? Again my search fragment derives from the leanback launcher searchfragment which i do not have access to modify.

Here are the erros in my logcat.

java.lang.RuntimeException: Unable to pause activity {xx.xxx.xxx.ui.SearchActivity}: java.lang.IllegalArgumentException: Service not registered: android.speech.SpeechRecognizer$Connection@561cef0

fire tvandroidamazon fling
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Levon@Amazon avatar image
Levon@Amazon answered

Hi osiris355,

Could you please specify the exact version of the Leanback library that you are using? Normally, the only special thing to do to get the search fragment working is comment out the startActivityForResult method in the setSpeechRecognitionCallback method in the onCreate of the SearchFragment as the documentation states. Thanks!

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sindy@Amazon avatar image
Sindy@Amazon answered

Hi Osiris. Thanks for posting. As per this doc:

https://developer.amazon.com/public/solutions/devices/fire-tv/docs/amazon-fire-tv-sdk-frequently-asked-questions

"Fire OS 5 includes both support for Android TV functionality and the Leanback support library. However, speech recognition with the Leanback library’s SearchFragment class is currently unsupported. See Implementing Search in Fire TV for more details."

1 comment
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

adam355 avatar image adam355 commented ·

Yes I have tried that but unfortunately that is not the only place the SpeechRecoginizer is stopped or started. In the parent SearchFragment class from the leanback library it calls the onPause where the SpeechRecognizer is destroyed.

You cannot modify this if you want to use the SearchFragment since the parent SearchFragment is ReadOnly. You also cannot stop its onPause method by overriding it in your child SearchFragment class. Google throws an error that you arent following through to the onPause super.

Due to this you cannot use any of the leanback library searching even though it is typing only.

@Override
public void onPause() {
    releaseRecognizer();
    super.onPause();
}

private void releaseRecognizer() {
    if (null != mSpeechRecognizer) {
        mSearchBar.setSpeechRecognizer(null); 
        mSpeechRecognizer.destroy(); //CRASHES HERE
        mSpeechRecognizer = null;
    }
}
0 Likes 0 ·
vallabh avatar image
vallabh answered

@osiris355 You can still avoid the crash by removing the onActivityResult in your searchActivity and putting the try catch block like this. This will help you to not to crash the application

mSpeechRecognitionCallback = new SpeechRecognitionCallback() {
    @Overridepublic void recognizeSpeech() {
        try {
            startActivityForResult(mFragment.getRecognizerIntent(), REQUEST_SPEECH);
        } catch (ActivityNotFoundException e) {

        }
    }
};
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.