Android Question Voice recognition setting intent

peacemaker

Expert
Licensed User
Longtime User
How to do this intent start in B4A ?


http://stackoverflow.com/questions/...e-google-voice-recognition-settings-in-my-app

B4X:
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();
}
}


This one start choosing many settings variants to manyally choose:
B4X:
Dim i As Intent
i.Initialize(i.ACTION_MAIN, "")
i.SetComponent("com.google.android.voicesearch.VoiceSearchPreferences")
i.Flags = 268435456    'FLAG_ACTIVITY_NEW_TASK
StartActivity(i)
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
THanks, Erel !
So, this code now is universal, i guess, allows to setup voice recognition in your B4A app and move back into the app:

B4X:
Dim i As Intent
i.Initialize("android.settings.INPUT_METHOD_SETTINGS", "")
StartActivity(i)
Try
    i.Initialize(i.ACTION_MAIN, "")
    i.SetComponent("com.google.android.voicesearch/com.google.android.voicesearch.VoiceSearchPreferences")
    i.Flags = 268435456    'FLAG_ACTIVITY_NEW_TASK
    StartActivity(i)
Catch
    Try
        i.Initialize(i.ACTION_MAIN, "")
        i.SetComponent("com.google.android.googlequicksearchbox/com.google.android.voicesearch.VoiceSearchPreferences")
        i.Flags = 268435456    'FLAG_ACTIVITY_NEW_TASK
        StartActivity(i)
    Catch
    End Try
End Try
End Sub

Tested in Android 4.2 and 5.0.
 
Last edited:
Upvote 0
Top