Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable speech to text button (Micro phone) on soft input keyboard in android programmatically

Thanks in advance for the help.

I am developing an android application for research purposes and need to disable the speech to text button on the soft input keyboard. The reason for this is due to concurrency issues that arise since the application I am developing uses the microphone. I understand that for a general application disabling keys is generally seen as impossible (since users may change default keyboards). I know for a fact that the default keyboard will be used.

With this in mind is it possible to disable certain keys? I believe that at the least I should be able to specify the input type such that the microphone button is hidden. I say this because if I disable speech to text in the settings (not programmatically, but manually as a user) the microphone icon is removed from the keyboard. I'm open to any possible solution (with the exception of not using the default keyboard) as this application will not appear on the play store.

like image 892
HXSP1947 Avatar asked Mar 14 '23 22:03

HXSP1947


1 Answers

You can't force the user input through anything other than pre-defined keyboards that already exist in the user's device.

The only way you could get around this is by programming your own custom, on-the-fly keyboard, and that is a very bad idea.

Just disable voice input programmatically by using XML declarations in the EditText you're looking at. You can do this with the attribute:

android:privateImeOptions="nm"   // nm stands for No Microphone.

If you want to set it programmatically you can try this::

        // deprecated i guess
        edt_txt.setPrivateImeOptions("nm");   
         // this one is new but it works only with Google Keyboard.
         edt_txt.setPrivateImeOptions("com.google.android.inputmethod.latin.noMicrophoneKey"); 

You can combine values in PrivateImeOptions parameter in CVS form so best option is to use:

                edt_txt.setPrivateImeOptions("nm,com.google.android.inputmethod.latin.noMicrophoneKey"); 

Take a look through here and see if you can find what you're looking for.

More info about Google Keyboard here -> look for method setOptions

like image 174
King of Masses Avatar answered Apr 25 '23 19:04

King of Masses