Search code examples
androidemojiimecustom-keyboard

Adding images to EditText from Custom IME


I'm working on a custom keyboard for Android, and I'm running into a problem. I need to either be able to output ASCII characters from the keyboard (i.e. ∅, ⌲, ⌓, etc), or be able to add images to the selected EditText from my keyboard. I know this is possible because Emoji does it with their keyboard. They have found a way to add images to any EditText, whether they created the EditText or not.

Does anyone have any idea how they accomplished this?


Solution

  • I came across this thread during some research and ended up elsewhere. Yes it is now possible to send images/GIF's to EditText's via a custom IME using the new CommitContent API introduced in 7.1 with backward compatibility till API level 13 - Honeycomb.

    Quote from : https://developer.android.com/guide/topics/text/image-keyboard.html#how_it_works

    enter image description here

    With Android 7.1 (API level 25), the Android SDK includes the Commit Content API, which provides a universal way for IMEs to send images and other rich content directly to a text editor in an app. The API is also available in v13 Support Library as of revision 25.0.0. We recommend using the Support Library because it runs on devices as early as Android 3.2 (API Level 13), and it contains helper methods that simplify implementation.

    I tested this with the latest update of hangouts and it works!.

    Sample code here: https://developer.android.com/about/versions/nougat/android-7.1-samples.html#img-kbd-ime

    I have merged the main app and the IME app code to a single project and here it is : https://github.com/satheeshwaran/ImageKeyboard-Android/tree/master

    UPDATE:

    I have published two apps using this API and I think they are doing good,

    https://play.google.com/store/apps/details?id=com.theweekendparty.indianmemekeyboard

    https://play.google.com/store/apps/details?id=com.theweekendparty.indiangifboardbollywood