Android Input Method -- force switch in the Code and obtain the current Input Method

Source: Internet
Author: User

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
Token
Supplies 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
ID
Unique 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"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.