title: How do I change the input method programatically?
body: <p>I have a requirement of changing the keyboard based on the change of language. </p>
  
  <p>I have done a bit of research and found that it can be done using these APIs </p>
  
  <blockquote>
    <ol>
    <li>InputMethodManager setInputMethod(android.os.IBinder, java.lang.String) </li>
    <li>InputMethodService switchInputMethod(java.lang.String)</li>
    </ol>
  </blockquote>
  
  <p>For the 1st API, I need an <strong>IBinder token</strong> which can be taken from <strong>InputMethodService</strong> instance by calling </p>
  
  <blockquote>
    <p>mInputMethodService.getWindow().getWindow().getAttributes().token</p>
  </blockquote>
  
  <p>or if I have the reference to <strong>InputMethodService</strong> object I can simply call </p>
  
  <blockquote>
    <p>mInputMethodService.switchInputMethod(id)</p>
  </blockquote>
  
  <p>to change the input method.</p>
  
  <p><strong>The real problem is how do I get a reference to InputMethodService object.</strong></p>
  
  <p><strong>PS:</strong> 
  I don't want to use InputMethodManager's showInputMethodPicker() because for my requirement I want to change
  it from my existing dialog which has a list of languages.</p>
  
  <p>I know that this is not possible for a user app but not sure if it's also not possible for a system app or not.</p>