How to show google voice recognition settings in my application?

I am working on an android application in which I implemented voice recognition and TTS. Therefore, I decided to launch the settings screen for Google and TTS voice recognition so that the user can change the settings from the application. I successfully completed TTS settings using the following code:

intent = new Intent(); intent.setAction("com.android.settings.TTS_SETTINGS"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(intent); 

Now I want to show the system "Google Voice Recognition Settings" in my application to allow the user to change the language settings, etc. I searched a lot ... I made a lot of hits and tried, but could not load the voice recognition settings screen, Please tell me how I can implement this. Thanks in advance...

+4
source share
2 answers

I am also stuck at this age ...

  Intent intent = new Intent(Intent.ACTION_MAIN); intent.setComponent(newComponentName("com.google.android.voicesearch","com.google.android.voicesearch.VoiceSearchPreferences")); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(intent); } 

Hope this is for you too ...

EDIT: As stated in the comments, this has changed in the Jelly Bean version of the Google Search application. To catch any possible upgrade issues when you cannot use Build.Version, you can use something in these lines:

 try { final Intent vsInt = new Intent(Intent.ACTION_MAIN); vsInt.setComponent(new ComponentName("com.google.android.voicesearch", "com.google.android.voicesearch.VoiceSearchPreferences")); vsInt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ctx.startActivity(vsInt); } catch (final Exception e) { try { final Intent vsjInt = new Intent(Intent.ACTION_MAIN); vsjInt.setComponent(new ComponentName("com.google.android.googlequicksearchbox", "com.google.android.voicesearch.VoiceSearchPreferences")); vsjInt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ctx.startActivity(vsjInt); } catch (final Exception e1) { e1.printStackTrace(); } } 
+5
source

@Brandall's answer for Android 5.1 does not work for me, for example, a different component name is used to determine the voice recognition settings.

 /** * Open speech recognition settings activity * * @return true in case activity was launched, false otherwise **/ public boolean openSpeechRecognitionSettings() { Intent intent = new Intent(Intent.ACTION_MAIN); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); boolean started = false; ComponentName[] components = new ComponentName[]{ new ComponentName("com.google.android.googlequicksearchbox", "com.google.android.apps.gsa.settingsui.VoiceSearchPreferences"), new ComponentName("com.google.android.voicesearch", "com.google.android.voicesearch.VoiceSearchPreferences"), new ComponentName("com.google.android.googlequicksearchbox", "com.google.android.voicesearch.VoiceSearchPreferences"), new ComponentName("com.google.android.googlequicksearchbox", "com.google.android.apps.gsa.velvet.ui.settings.VoiceSearchPreferences") }; for (ComponentName componentName : components) { try { intent.setComponent(componentName); startActivity(intent); started = true; break; } catch (final Exception e) { Timber.e(e, null); } } return started; } 

EDIT: updated with last component name

+9
source

Source: https://habr.com/ru/post/1391079/


All Articles