Finding if external usb or bluetooth keyboard attached in Android

前端 未结 1 752
你的背包
你的背包 2020-12-09 06:26

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().getC

相关标签:
1条回答
  • 2020-12-09 07:24

    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
       }
    
     }
    
    0 讨论(0)
提交回复
热议问题