问题描述
谁能告诉我是否有任何方法可以找出蓝牙 qwerty 键盘是否连接到 android 设备.
我尝试使用 getresources().getconfiguration.keyboard,但无论是否连接键盘,它总是给我相同的值.
谢谢
实现此目的的一种方法是将 android:configchanges="keyboard" 添加到 androidmanifest.xml 文件中的活动中.p>
有了这个,你可以覆盖 onconfigurationchanged 每当插入或拔出键盘时都会调用它
@override公共无效 onconfigurationchanged(配置新配置){如果(newconfig.hardkeyboardhidden == configuration.hardkeyboardhidden_no){//正在连接一个硬件键盘}否则如果(newconfig.hardkeyboardhidden == configuration.hardkeyboardhidden_yes)//一个硬件键盘正在断开连接}}
can anyone please tell me if there is any way we can find out if a bluetooth qwerty keyboard is attached to android device.
i tried working with getresources().getconfiguration.keyboard, but it always gives me the same value whether key board is attached or not.
thanks
one way to do this is adding android:configchanges="keyboard" to the activity in your androidmanifest.xml file.
with this you can override onconfigurationchanged which will be called whenever a keyboard is plugged in or plugged out
@override public void onconfigurationchanged(configuration newconfig) { if(newconfig.hardkeyboardhidden == configuration.hardkeyboardhidden_no) { //a hardware keyboard is being connected } else if(newconfig.hardkeyboardhidden == configuration.hardkeyboardhidden_yes) //a hardware keyboard is being disconnected } }