Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding if external usb or bluetooth keyboard attached in Android

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

like image 614
Timm Carnot Avatar asked Aug 28 '12 14:08

Timm Carnot


People also ask

Can Android phone connect to Bluetooth keyboard?

Bluetooth Keyboard to Android – PairingYou can pair a bluetooth keyboard easily, as you pair any bluetooth device. First, go to Settings and enable Bluetooth in your device. Then, your phone or tablet will detect the available Bluetooth keyboard and pairing will be done almost automatically.

Is there an external keyboard for Android phone?

Via Bluetooth For this method, you will need to buy a Bluetooth keyboard setup. There are many good options on the market. These keyboards come in small, medium and regular sizes and work reliably well, with long battery life. Once you have a Bluetooth keyboard, turn it on to make it discoverable.


1 Answers

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
   }

 }
like image 117
Leon Lucardie Avatar answered Nov 15 '22 22:11

Leon Lucardie