检测android虚拟键盘的类型

检测android虚拟键盘的类型,android,android-softkeyboard,android-virtual-keyboard,Android,Android Softkeyboard,Android Virtual Keyboard,我有一个android应用程序,它处理来自标准键盘的输入,与Swype键盘提供的输入不同。有没有办法通过编程找出当前正在使用的键盘 谢谢 最好的方法是使用InputDeviceId int[] devicesIds = InputDevice.getDeviceIds(); for (int deviceId : devicesIds) { //Check the device you want InputDevice device = InputDevice.getDevice

我有一个android应用程序,它处理来自标准键盘的输入,与Swype键盘提供的输入不同。有没有办法通过编程找出当前正在使用的键盘


谢谢

最好的方法是使用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
}
参考:


使用安全静态内部设置类获取默认键盘类型

String defaultKeyboard = Settings.Secure.getString(context.getContentResolver(),
                    Settings.Secure.DEFAULT_INPUT_METHOD);
返回类型将是一个由“/”分隔的字符串序列,因此将该字符串wrt拆分为斜杠以获得子字符串列表。 该列表的第一个元素将为您提供默认键盘的软件包名称

defaultKeyboard = defaultKeyboard.split("/")[0];
提示-包装设置的良好实践。使用try-catch保护呼叫