Is there a way in Android to tell if a users device has an actual keyboard or not?

别来无恙 提交于 2019-12-09 13:13:43

问题


I would like to detect if the current users phone has a hardware keyboard or only a on-screen keyboard. Is this possible with the SDK?


回答1:


Yes, you can.

Fetch the Configuration object using

Configuration config = getResources().getConfiguration();

...and then look at the keyboard field.

If they value of keyboard is not KEYBOARD_NOKEYS, the user has a hardware keyboard.

Note that as @Carl says in his comment below, the user may attach a USB keyboard at any point while your app is running, causing the value of keyboard to change.



来源:https://stackoverflow.com/questions/6654177/is-there-a-way-in-android-to-tell-if-a-users-device-has-an-actual-keyboard-or-no

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