Forced conversion Input Method
1. inputmethodmanager. setinputmethod (ibinder token, string ID)
Public void setinputmethod (ibinder token, string ID)
Force switch to a new input method component. This can only be called from the currently active input method, as validated by the given token.
Parameters
TokenSupplies the identifying token given to an input method when it was started, which allows it to perform this operation on itself.
IDThe unique identifier for the new input method to be switched.
This function, of course, can implement forced switching of the input method. However, obtaining ibinder requires certain permissions and calling needs to be more in-depth. This function has not been specially developed by fellow developers for a while. In the future, let's discuss it in depth. Dear friend, please leave a message. Thank you very much !!
2. inputmethodservice. switchinputmethod (string ID)
Public void switchinputmethod (string ID)
Since: API Level 3 force switch to a new input method, as identified by ID. This input method will be destroyed, and the requested one started on the current input field.
Parameters
IDUnique Identifier of the new input method ot start.
This is much simpler than the first API. In the most intuitive sense, you don't need to obtain the corresponding ibinder here! We have almost won, but we still need to break this layer of paper.
First, where can I call this API?
This API belongs to the class inputmethodservice, And the entry class of each input application inherits from this class. Therefore, you can call this API in the input method entry class. For example, the Google Pinyin input method provided in the Google SDK can be called in the pinyinime. Java class!
What is the parameter ID?
In terms of definition, it is a string type, and Google's interpretation is not general. After careful research, I found that this was the case. I suggest you use the example above. The Google PinYin Input Method ID is com. Android. inputmethod. Pinyin/. pinyinime. The complete call method is: switchinputmethod ("com. Android. inputmethod. Pinyin/. pinyinime ");
So how can I call it if it is not in the entry class?
Define private pinyinime mimeservice in the class to be called;
You can call mimeservice. switchinputmethod ("com. Android. inputmethod. Pinyin/. pinyinime ");
3. settings. Secure. putstring (contentresolver resolver, string name, string value) (Android. provider. settings)
For exampleSettings. Secure. putstring (inputchange. This. getcontentresolver (),
Settings. Secure. default_input_method, "com. Android. inputmethod. Pinyin/. pinyinime"); (here inputchange is an activity written by myself)
This is the simplest and the final performer.
In fact, when we call the second method, it will call the first method, and the first method will call the third method,
Obtain the current Input Method
Settings. Secure. getstring (contentresolver resolver, string name)
For exampleString Ss = settings. Secure. getstring (inputchange. This. getcontentresolver (),
Settings. Secure. default_input_method); (here inputchange is an activity written by myself)
In this way, the ID of the current input method type can be obtained. The result of the current input method in the current system is "com. android. inputmethod. pinyin /. pinyinime "so the SS result is" com. android. inputmethod. pinyin /. pinyinime"