Dynamically Switching Keyboards on Zebra Android Devices

Darryn Campbell -
3 MIN READ

Last month I wrote about how to switch keyboard layouts on the fly using the Enterprise Keyboard and its API, the use case being that some screens in your app would require different methods of data entry. As I said in my previous post the Enterprise Keyboard is not a general-purpose replacement keyboard and the standard keyboard should be used for standard data or text entry.

What if some screens in your app require special data entry and other screens require standard text entry? In this scenario it makes sense to use the Enterprise Keyboard for those special data entry screens and the standard keyboard for the rest of your application. This post will describe how to dynamically switch between the Enterprise Keyboard and the keyboard which ships as part of your standard Android installation.

There are three different keyboards you will likely encounter when developing your app:

  • Enterprise Keyboard: supports custom layouts and is used for unique data entry scenarios.
  • Gboard: Android’s standard keyboard which ships with all GMS Android devices.
  • AOSP keyboard: Android’s standard keyboard from the Open Source project. Less common on recent devices than the Gboard but will still be seen on Restricted GMS devices and devices running AOSP builds.

You can dynamically switch between keyboard layouts using the MX UI Manager’s Set Default Input Method. Whilst most commonly seen in the context of staging, many of the MX capabilities, including this one, are available through the EMDK’s processProfile method.

Prerequisites

  • In order to switch keyboards, you will need to have the desired keyboards installed on your device.
  • Enterprise Keyboard may not be pre-installed and can be downloaded from the support portal if required.
  • You will not have both the Gboard and AOSP keyboard available, only one or the other.
    • Note that devices in Restricted GMS are a special case and when entering Restricted GMS mode, the AOSP keyboard is enabled and the Gboard is disabled.

Code

To switch between keyboards it is necessary to create an MX profile for each keyboard you want to switch to, specifying the package name and class name of that keyboard. The packages and classes of the 3 common keyboards are given below:

Enterprise Keyboard: Package = com.symbol.mxmf.csp.enterprisekeyboard ClassName = com.android.inputmethod.latin.LatinIME

Gboard: Package = com.google.android.inputmethod.latin ClassName = com.android.inputmethod.latin.LatinIME

AOSP Keyboard: Package = com.android.inputmethod.latin ClassName = com.android.inputmethod.latin.LatinIME

The MX profile to set the Enterprise Keyboard as the Default IME (for example) is:

<characteristic type="Profile">
  <parm name="ProfileName" value="KeyboardEKB">
  <parm name="ModifiedDate" value="2020-01-16 13:38:32">
  <parm name="TargetSystemVersion" value="4.4">
  <characteristic type="UiMgr" version="4.3">
    <parm name="emdk_name" value="ekb">
    <parm name="InputMethodAction" value="1">
    <characteristic type="InputMethodDetails">
      <parm name="InputMethodOption" value="4">
      <parm name="InputMethodPackageName" value="com.symbol.mxmf.csp.enterprisekeyboard">
      <parm name="InputMethodClassName" value="com.android.inputmethod.latin.LatinIME">
    </parm></parm></parm></characteristic>
  </parm></parm></characteristic>
</parm></parm></parm></characteristic>

And you apply this Profile using the EMDK as follows:

String[] modifyData = new String[1];
modifyData[0] = "";
EMDKResults results = profileManager.processProfile("KeyboardEKB",
        ProfileManager.PROFILE_FLAG.SET, modifyData);

Provided EKB is installed, the change will take effect immediately.

A sample app is available to show how to switch between keyboards using the technique described above at https://github.com/darryncampbell/KeyboardSwitcher

Architecture

Above: Switching to the Enterprise keyboard

Architecture

Above: Switching to the Gboard

Architecture

Above: Switching to the AOSP keyboard, having first put the device into GMS Restricted mode to ensure availability of the AOSP keyboard.

I also put together a 20 second demo video of the sample app in action, switching between EKB and Gboard: https://www.youtube.com/watch?v=CbxTqthuK_M

Keyboard Switcher Youtube Demo

profile

Darryn Campbell

Please register or login to post a reply

Replies