this is my onConfigurationChanged :
@Override
public void onConfigurationChanged(Configuration newConfig) { //this will change the language, if needed.
super.onConfigurationChanged(newConfig);
Log.i("onConfigurationChanged", "keyboard: " + getResources().getConfiguration().keyboard);
if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
//A hardware keyboard is being connected
Log.i("onConfigurationChanged", "HARDKEYBOARDHIDDEN_NO");
} else if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
//A hardware keyboard is being disconnected
Log.i("onConfigurationChanged", "HARDKEYBOARDHIDDEN_YES");
}
Utils.setLocale(getBaseContext(), newConfig);
}
And this is my activity:
<activity
android:name="com.vidyo.vidyomod.activities.VMBaseActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleInstance"
android:screenOrientation="landscape"
android:windowSoftInputMode="adjustResize">
</activity>
Why isn't onConfigurationChanged called then? when I plug/unplug the keyboard? Cause I've set the configChanges, I need to find a way to know when I have a usb keyboard plugged or not.
PS: getActivity().getResources().getConfiguration().hardKeyboardHidden returns 2 => HARDKEYBOARDHIDDEN_YES even if my usb keyboard is connected. why?
EDIT: Even if onConfigurationChanged is not called: I get this logs:
07-12 07:40:41.749: D/EventHub(997): No input device configuration file found for device 'LITEON Technology USB Multimedia Keyboard'.
07-12 07:40:41.759: I/EventHub(997): New device: id=11, fd=195, path='/dev/input/event7', name='LITEON Technology USB Multimedia Keyboard', classes=0x80000403, configuration='', keyLayout='/system/usr/keylayout/Generic.kl', keyCharacterMap='/system/usr/keychars/Generic.kcm', builtinKeyboard=false, usingSuspendBlockIoctl=true, usingClockIoctl=true
07-12 07:40:41.759: I/InputReader(997): Device added: id=11, name='LITEON Technology USB Multimedia Keyboard', sources=0x00002103
Cant I take this from somewhere? like a event listener on the EventHub or something?
I had a similar problem with a Samsung bluetooth keyboard for Samsung Tab S2.
My onConfigurationChanged()
method did not fire until I put this line into the manifest.
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|navigation"
The only documentation I could find was here.
The navigation
keyword refers to the touchpad, which most physical devices have, and which most soft keyboards do not.
To quote the doco: The navigation type (trackball/dpad) has changed. (This should never normally happen.)
A fine example of poor android documentation being as costly as poor code!
User contributions licensed under CC BY-SA 3.0