开发者

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

开发者 https://www.devze.com 2023-03-19 05: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?Yes, you can.

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号