[Android] TV: Do not set voice search if not available

Geoffrey Métais git at videolan.org
Wed Oct 11 17:09:20 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Oct 11 17:06:31 2017 +0200| [70036e0144d48fad2a088b0176f4238af755381a] | committer: Geoffrey Métais

TV: Do not set voice search if not available

> https://code.videolan.org/videolan/vlc-android/commit/70036e0144d48fad2a088b0176f4238af755381a
---

 .../src/org/videolan/vlc/gui/tv/SearchActivity.java  | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/SearchActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/SearchActivity.java
index a8fa1fee0..310598ca7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/SearchActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/SearchActivity.java
@@ -29,6 +29,7 @@ import android.support.v17.leanback.widget.SpeechRecognitionCallback;
 import android.support.v4.app.FragmentActivity;
 
 import org.videolan.vlc.R;
+import org.videolan.vlc.util.Util;
 
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
 public class SearchActivity extends FragmentActivity {
@@ -43,18 +44,21 @@ public class SearchActivity extends FragmentActivity {
 
         mFragment = (SearchFragment) getSupportFragmentManager()
                 .findFragmentById(R.id.search_fragment);
-        Intent intent = getIntent();
+        final Intent intent = getIntent();
         if (Intent.ACTION_SEARCH.equals(intent.getAction()) || "com.google.android.gms.actions.SEARCH_ACTION".equals(intent.getAction())) {
             mFragment.onQueryTextSubmit(intent.getStringExtra(SearchManager.QUERY));
         } else {
-            SpeechRecognitionCallback speechRecognitionCallback = new SpeechRecognitionCallback() {
+            final Intent recognitionIntent = mFragment.getRecognizerIntent();
+            if (Util.isCallable(recognitionIntent)) {
+                final SpeechRecognitionCallback speechRecognitionCallback = new SpeechRecognitionCallback() {
 
-                @Override
-                public void recognizeSpeech() {
-                    startActivityForResult(mFragment.getRecognizerIntent(), REQUEST_SPEECH);
-                }
-            };
-            mFragment.setSpeechRecognitionCallback(speechRecognitionCallback);
+                    @Override
+                    public void recognizeSpeech() {
+                        startActivityForResult(recognitionIntent, REQUEST_SPEECH);
+                    }
+                };
+                mFragment.setSpeechRecognitionCallback(speechRecognitionCallback);
+            }
         }
     }
 



More information about the Android mailing list