Keyboard Support

Contact and Search

Keyman.com Homepage

Header bottom

Keyman.com

Other versions
Version 14.0Version 13.0 (current release)Version 12.0Version 11.0Version 10.0Version 2.0

On this page

Guide: build an in-app keyboard

Keyman Engine for Android allows you to use any Keyman touch keyboard in your Android app, or even to create your own system keyboard app for purchase in the Play Store.
This guide will walk you through the steps for creating your first Android app with Keyman Engine for Android.

If you are not familiar with Android development, you will find the Android Developer online training an invaluable resource, and working through some of their tutorials first will help you with the rest of this guide.

1. Install Free Tools

  1. Install Keyman Developer 10 or later.
  2. Install Java SE Development Kit.
  3. Install Android Studio.
  4. Android Studio runs on several platforms. Keyman Developer 10 runs on Windows 7 or later.

2. Configure Android Studio

  1. For Windows users, from Control Panel>System>System Properties>Environment Variables,
    create a system variable ANDROID_HOME to the location of your Android SDK. The default installation location is
    c:\Users\[USER]\AppData\Local\Android\sdk where [USER] is your Windows username.
  2. For Linux users, add the following to ~/.bashrc
  3. export ANDROID_HOME=$HOME/Android/Sdk
    export PATH=$PATH:$ANDROID_HOME/tools
    
  4. In a command prompt or terminal, accept all the SDK license agreements
  5. cd c:\Users\[USER]\AppData\Local\Android\sdk\tools\bin
    yes | ./sdkmanager.bat --licenses
    

3. Download Keyman Engine for Android and Build Sample projects

  1. Download the Keyman for Android SDK and extract the files to a new folder.

The archive includes two sample projects and an Android .aar library file. This guide will use the first example project, KMSample1.

  1. If KMSample1.zip exists, extract it to a new folder. Otherwise, the KMSample1 project can be found at Samples/KMSample1
  2. In Android Studio, select File>Open and choose the KMSample1 project folder from the previous step.
  3. When the project loads, you may be prompted to install Android SDKs; go ahead and follow the prompts to fixup any missing SDK dependencies.

4. Create a keyboard layout

Use Keyman Developer to build a touch layout. The following blog posts walk through some of the development and testing for creating a touch keyboard layout:

When your keyboard is ready, you should have a compiled keyboard Javascript file. The example below shows the Tamil Mobile99 touch layout.

Keyman-developer

Open the containing folder for the keyboard to find the Javascript file to copy over; its name will be based on your source keyboard name.

Keyman-developer-open-containing-folder

Compiled-keyboard-file

5. Add your keyboard to the project

Copy your compiled keyboard file (in this example tamil99m-1.1.js) to the KMSample1\app\src\main\assets\cloud folder. If you have a font, then copy that to the assets\cloud folder. This example uses aava1.ttf

Copy-keyboard-file

When you switch back into Android Studio, you should see the cloud folder with your keyboard and font files:

Android-studio-assets

Next, edit MainActivity.onCreate() to add the keyboard (tamil99m) with KMManager. If you're not using a custom font (this example uses aava1.ttf), you can set KMKey_Font to the default font:

  // Add a custom keyboard
  HashMap<String, String> kbInfo = new HashMap<String, String>();
  kbInfo.put(KMManager.KMKey_PackageID, "cloud");
  kbInfo.put(KMManager.KMKey_KeyboardID, "tamil99m");
  kbInfo.put(KMManager.KMKey_LanguageID, "ta");
  kbInfo.put(KMManager.KMKey_KeyboardName, "Tamil 99M");
  kbInfo.put(KMManager.KMKey_LanguageName, "Tamil");
  kbInfo.put(KMManager.KMKey_KeyboardVersion, "1.1");
  kbInfo.put(KMManager.KMKey_Font, "aava1.ttf");
  //kbInfo.put(KMManager.KMKey_Font, KMManager.KMDefault_KeyboardFont); // Use the default font
  KMManager.addKeyboard(this, kbInfo);

Android-studio-adding-keyboard

Finally, add code to select the keyboard once it has been loaded. Locate the onKeyboardLoaded function, and add one line to it:

  @Override
  public void onKeyboardLoaded(KeyboardType keyboardType) {
    // Handle Keyman keyboard loaded event here if needed
    int kbIndex = KMManager.getKeyboardIndex(this, "tamil99m", "ta");
    KMManager.setKeyboard(this, kbIndex);
  }

6. Build and run the app

You can run your app on a created Virtual Device, or connect an Android device via USB to your computer to test. In either case, click the green Run button to start the app. The steps below show how to create a new Virtual Device

Android-studio-starting-debug

Click the [Create Virtual Device] button to add a new virtual device, and follow the prompts. Any recent emulated device should work fine. You will be prompted to download additional resources for the emulator when this runs.

Android-emulator-tamil

And there you have it: your first Keyman Engine for Android app!

See Also