如何检查是否使用本机/硬件键盘?
我想检查是否使用了本机/硬件键盘,如果可能的话我想禁用第三方键盘。
我的目标很简单,我只使用本机 android 软键盘在编辑框中输入值,其他键盘不应该能够做到这一点
谢谢
编辑
我知道做我正在尝试的事情不是一个好主意要做到这一点,我知道android的基本思想是拥有意图、活动和服务,它们知道根据意图过滤器处理某些类型的意图。但这在每条规则中都有一个例外,尤其是当我们谈论安全时。
我想禁用所有第三方键盘,如果无法使用某些 API 或其他东西来做到这一点......这个问题有什么解决方法吗?
编辑
String s=Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
这将返回当前启用的输入法(键盘),但我需要类似“系统键盘”的东西,但我没有看到任何类似的标志:-(。
List<InputMethodInfo> list = m.getInputMethodList();
一种可能的解决方案是采用列表[0] 作为我正在搜索的键盘,但我不想转发订单(除非订单保证索引为 0 的键盘始终是随手机安装的键盘),
这是列表的值
[InputMethodInfo{com.htc.android.htcime/.HTCIMEService, settings: com.htc.android.htcime.HTCIMESettings}, InputMethodInfo{com.volosyukivan/.WiFiInputMethod, settings: null}]
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}]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
像这样的东西应该让您检查用户是否使用非标准键盘。但是,与其阻止他们使用此键盘,不如提供有关可能的安全风险的有用警告消息怎么样?
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?
您可以使用
Configuration
对象来查看设备的硬件键盘是否被隐藏。通常,这意味着他们正在使用该键盘,因为大多数设备在硬件键盘可用时不会显示 IME。但是,某些设备可能同时支持两者,并且我不知道外部键盘(USB、蓝牙)如何与该值交互。幸运的是,这是不可能的。
问题中到目前为止没有提到任何问题。
如果用户选择使用替代键盘,这是他们作为用户的选择。如果用户愿意,他们完全可以切换键盘。用户完全有能力做出这些决定。由于设备加载了来自该因素的间谍软件,例如 CarrierIQ。因此,您认为通过攻击用户的键盘选择来提高安全性的假设从根本上是有缺陷的。
当然,您根本不必支持使用任何键盘,从而迫使用户使用您自己设计的某种屏幕输入选项。这也不是完全安全的(例如,窃听攻击),并且对于出于特定原因选择某些第三方键盘的人(例如,盲人用户、有电机控制问题的用户)可能会导致可用性问题。
我不知道有一种方法可以明确确定固件自己的 IME 是什么,特别是因为这因设备和固件而异。
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.Fortunately, this is not possible.
There is no problem cited to this point in the question.
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.
我找到精确的解决方案
I find precise solution