如何检测Android设备中的硬件键盘?

时间:2018-02-15 07:21:42

标签: android xamarin xamarin.android

我需要检测Android设备是否具有物理键盘。我使用的是Resources.Configuration.Keyboard,但它始终返回Android.Content.Res.KeyboardType.Nokeys。为了测试我正在使用带有硬件键盘的真正的Android设备。我错过了什么?

平台:Xamarin Android

1 个答案:

答案 0 :(得分:0)

Finding if external usb or bluetooth keyboard attached in Android

 @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
   }

 }

https://developer.android.com/reference/android/content/res/Configuration.html#keyboard