crypto9294
crypto9294

Reputation: 171

Detect type of virtual keyboard-android

I have an android application which handles input from Standard keyboard differently from input given by Swype keyboard. Is there any way to programmatically find out which keyboard is currently being used?

Thanks!

Upvotes: 0

Views: 2740

Answers (2)

shubham chouhan
shubham chouhan

Reputation: 981

Use Secure static inner class of Settings to get a default keyboard type.

String defaultKeyboard = Settings.Secure.getString(context.getContentResolver(),
                    Settings.Secure.DEFAULT_INPUT_METHOD);

Return type will be a string sequence separated by "/", so split this string wrt to slash to get a list of substrings. The 1st element of that list will give you the package name of your default keyboard.

defaultKeyboard = defaultKeyboard.split("/")[0];

P.S - Good practice to wrap Settings.Secure calls with try catch.

Upvotes: 1

Koza
Koza

Reputation: 61

The best way to get that is using the InputDeviceId.

int[] devicesIds = InputDevice.getDeviceIds();
for (int deviceId : devicesIds) {
    //Check the device you want
    InputDevice device = InputDevice.getDevice(deviceId);
    //device.getName must to have virtual
    //That check the keyboard type
    device.getKeyboardType(); //returns an int
}

Reference:

https://developer.android.com/reference/android/view/InputDevice.html#getKeyboardType%28%29

Upvotes: 4

Related Questions