How to check if the native/hardware keyboard is used?

一世执手 提交于 2019-12-21 02:43:11

问题


I want to check if the native/hardware keyboard is used, and also if possible I want to disable the third party keyboards.

My goal is simple I use just the native android soft keyboard for entering values in my edit boxes and no other keyboard should be able to this

Thanks

EDIT

I know it is not good idea to do what I am trying to do, I know that the basic idea of android is to have intents and activities and services who know to handle some types of intent according intent-filter. But this in every rule there is an exception, especially when we talk about security.

I want to disable all third party keyboards, and if this is not possible to do it with some API or something... is there any workaround to this problem ?

EDIT

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

This returns the currently enabled input method (keyboard),but I need something like the 'system keyboard' and I do not see any flag like that :-(.

List<InputMethodInfo> list = m.getInputMethodList();

One possible solution is to take the list[0] as the keyboard I am searching, but I do not want to relay on the order (except if the order is garanteed that always the keyboard with index 0 is the one that comes install with the phone)

this is the value of list

[InputMethodInfo{com.htc.android.htcime/.HTCIMEService, settings: com.htc.android.htcime.HTCIMESettings}, InputMethodInfo{com.volosyukivan/.WiFiInputMethod, settings: null}]

回答1:


I want to check if the native/hardware keyboard is used

You can use the Configuration object to see if the device's hardware keyboard is hidden. Usually, that would imply they are using that keyboard, since most devices do not show an IME when the hardware keyboard is available. However, some devices might support both simultaneously, and I don't know how external keyboards (USB, Bluetooth) interact with this value.

also if possible I want to disable the third party keyboards.

Fortunately, this is not possible.

is there any workaround to this problem ?

There is no problem cited to this point in the question.

yes the will not be happy, but they will be much more unhappy if you let their secure data to be corrupt

If users choose to use an alternative keyboard, that is their choice as users. The user is perfectly capable of switching keyboards if they wish. The user is perfectly capable of making these decisions. It is entirely possible that an alternative keyboard is more secure than a built-in one, due to devices loaded with spyware from the factor, such as CarrierIQ. Hence, your assumption that you are improving security by attacking the user's choice of keyboard is fundamentally flawed.

Of course, you do not have to support using any keyboard at all, forcing users to use some sort of on-screen input option that you devise yourself. This is not completely secure either (e.g., tapjacking attacks), and it may cause usability problems for people who chose certain third-party keyboards for specific reasons (e.g., blind users, users with motor control issues).

I am not aware that there is a way to definitively determine what the firmware's own IME is, particularly since this varies by device and firmware.




回答2:


Something like this should let you check if the user is using a non-standard keyboard. However, instead of preventing them using this keyboard, how about a helpful warning message about the possible security risks?

public boolean isUsingCustomInputMethod() {
    InputMethodManager imm = (InputMethodManager) mCtx.getSystemService(
        Context.INPUT_METHOD_SERVICE);
    List<InputMethodInfo> mInputMethodProperties = imm.getEnabledInputMethodList();
    final int N = mInputMethodProperties.size();
    for (int i = 0; i < N; i++) {
        InputMethodInfo imi = mInputMethodProperties.get(i);
        if (imi.getId().equals(
            Settings.Secure.getString(mCtx.getContentResolver(),
                    Settings.Secure.DEFAULT_INPUT_METHOD))) {
            if ((imi.getServiceInfo().applicationInfo.flags & 
                ApplicationInfo.FLAG_SYSTEM) == 0) {
                return true;
            }
        }
    }
    return false;
}



回答3:


I find precise solution

InputMethodManager m = (InputMethodManager) ctx.getSystemService("input_method");
List<InputMethodInfo> a = m.getInputMethodList();
for (InputMethodInfo inputMethodInfo : a) {
        if (inputMethodInfo.getIsDefaultResourceId() == 0) {
            //it is not default
            return false;
        }
}
//it is default
return true;


来源:https://stackoverflow.com/questions/8165618/how-to-check-if-the-native-hardware-keyboard-is-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!