title: Embedding emoji(emoticons images) to custom softkeyboard android
body: <p>I have created a custom soft Keyboard(IME) where we can add custom emoji. </p>
  
  <p>Whenever i try to <strong>add my emoticons to it. it override the last text entered. i mean it dont append</strong> the emoticons unless it override it. how can i add emoji to currentInputConnection</p>
  
  <p>for example </p>
  
  <pre><code>i image write  hello image abcimage          ///where image represents emoji
  </code></pre>
  
  <p>it becomes </p>
  
  <pre><code>i image write hello image image
  </code></pre>
  
  <p>// and i can add image after space easily or i can repeatedly add images easily .</p>
  
  <p>when i add text it appends to emoji but when i add emoji after entering some text it remove the text and then add it self(emoji image).</p>
  
  <p>Just for testing purpose i put emoji code to shift key</p>
  
  <p><strong>Problem code</strong> </p>
  
  <pre><code>else if (primaryCode == Keyboard.KEYCODE_SHIFT) 
          {
          //  this.handleShift();
  
              //this.mComposing.append(getSmiledText(getApplicationContext(), ":)"));
  
               ImageGetter imageGetter = new ImageGetter() 
                  {
                      public Drawable getDrawable(String source) {
                          Drawable d = getResources().getDrawable(R.drawable.e041);
                          d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
                          return d;
                      }
                  };
  
                  Spanned cs = Html.fromHtml("&lt;img src='" + getResources().getDrawable(R.drawable.e041) + "'/&gt;", imageGetter, null);
  
                //  getCurrentInputConnection().commitText(cs, 1);
  
                 // this.mComposing.append(cs);
  
  
              //getCurrentInputConnection().commitText(getSmiledText(getApplicationContext(), ":)"), 1);
  
  
               getCurrentInputConnection().beginBatchEdit();
  
  
               getCurrentInputConnection().commitText(cs, 1);
  
               getCurrentInputConnection().endBatchEdit();
  
  
              //getCurrentInputConnection().setComposingText(cs, 1); // it is giving wrong 
  
  
          } 
  </code></pre>
  
  <p>And tried multiple ways to solve it ,some tried codes are shown in comments </p>
  
  <p>Simple Words : I want to append emoji image to text, but when i add image to text, it remove the written text, how can i solve.  <strong>full source can't be shown it is lengthy. Ask me if you need any method in my class</strong></p>
  
  <p>Related link : </p>
  
  <p><a href="https://stackoverflow.com/questions/25240548/add-custom-image-as-emoji-in-android?lq=1">add custom image as Emoji in android</a></p>
  
  <p><a href="https://stackoverflow.com/questions/24100615/cannot-add-an-image-to-my-keyboard-service">https://stackoverflow.com/questions/24100615/cannot-add-an-image-to-my-keyboard-service</a></p>
  
  <p><a href="https://stackoverflow.com/questions/16768930/implementations-of-emoji-emoticon-view-keyboard-layouts">Implementations of Emoji (Emoticon) View/Keyboard Layouts</a></p>
  
  <p>Thanks in Advance.  </p>