Per-application input setting on Android Device - android

Android keyboard has a button that switches the input language. How can I change the input language
programmatically without using this button? My app has different textboxes where the user enters information in different languages and when the user switches from one field to another the input language will be changed automatically to the correct one.
Android keyboard is a stand-alone application, so I need to manage this language changing from my application. The only thing that I found is switchToNextInputMethod() method in InputMethodManager class but I'm not sure if it fits.

Related

How to show a keyboard for a Presentation Class on a Secondary Screen?

I am creating an App for Dual Screen by using Presentation API for showing a separate view for Customer, in which there is an input field (EditText), which asks the customer to input depending on type of fields. Now, the issue is that the softkeyboard only appears on the main screen & not the secondary screen, due to which only the person facing main screen will be able to input values in EditText. But I want to open softkeyboard on both sides, not both at the same time and atleast they should be able to open it one at a time.
If I try to forcibly open the keyboard it still opens on the other side (main screen) only.
If you were using Android 10:
From:
https://developer.android.com/guide/topics/ui/foldables#software_keyboard
Software keyboard
A keyboard can be shown on a secondary screen if the display is configured to support system decorations. The input method editor will automatically show up if a text field requests input on that display.
While leads to:
Android Open Source Project - Input Method Editor Support
https://source.android.com/devices/tech/display/multi_display/ime-support
and that page has a lot of detail on the various implementation & security issues on having a multiple display IME.
As you mentioned a custom device running Android 7.1 unless the manufacturer has modified for system decorations:
From that AOSP page on IME support:
In Android 9 (and lower), the IME was only available on the default screen...
So from stock AOSP you can't have the native IME appear outside of the default display.
I can only suggest reaching out to the manufacturer to see if they have a custom SDK for that feature, else you will have to create your own IME-like view, assuming you can get touch events from the secondary display.

Android soft keyboard is not changing programmatically

I am trying to change the android default keyboard to another soft keyboard that has already installed.
for achieving this task I tried this code,
imeManager.setInputMethod(txtSearch.getWindowToken(),
"lk.bhasha.helakuru/.SinhalaSoftKeyboard");
but the keyboard is not changing.
How do I switch the android soft keyboard to another already installed?
Thanks.
For security reasons, it's not possible to change the keyboard programmatically, unless your application is an IME.
From the documentation:
A client application can ask that the system let the user pick a new IME, but can not programmatically switch to one itself. This avoids malicious applications from switching the user to their own IME, which remains running when the user navigates away to another application. An IME, on the other hand, is allowed to programmatically switch the system to another IME, since it already has full control of user input.

Controlling the input language keyboard programatically from the android app.

The problem is that when I change the language of my android device to Hindi, it changes the keyboard to Hindi as well.But I want that the app should appear in Hindi but English keyboard should always open inside the app.I want that it should be done programatically through the app instead of changing the devive settings.
No you cannot. Android has restricted this for security reasons. If you can manipulate the input method, you can do things like key logging, hence tampering privacy. You could however use the InputManager and let the user select an input method:
InputMethodManager ime=(InputMethodManager)getActivity().getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if(ime!=null) {
ime.showInputMethodPicker();
}
But the above code will only show the active keyboard set the user in Settings.

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.
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
To disable microphone button on multiple keyboard. Use property
android:privateImeOptions="nm"
But it will not work for Gboard(google native keyboard)
To disable on microphone on Gboard use
android:privateImeOptions="nm"
editText.setImeOptions(IME_FLAG_NO_PERSONALIZED_LEARNING)
Just use this in your editText on the layout file:
android:imeOptions="flagNoPersonalizedLearning"

Get state of soft input keyboard on Android

I have an EditText in my Android app, with a normal keyboard attached to it, e.g. there are no custom filters, or other restrictions set on it. I would like to find out if the user uses the QWERTY keyboard, or she switched to another type, for example to the one where the numbers are displayed, and other special characters. Is this possible?
Thanks.

Categories

Resources