Android text and input-spell checker (1)

Source: Internet
Author: User

This article translated from: http://developer.android.com/guide/topics/text/spell-checker-framework.html

The Android platform provides a spell checker framework that allows you to execute and access spell checking in your application. This framework is one of the text service APIs provided by the Android platform.

To use this framework in an application, you need to create a special android service type, which generates a Session Object of the spelling checker. Based on the text you provided, the session object will return the spelling suggestions generated by the spelling checker.

Life cycle of the spell checker

Shows the life cycle of the spelling checker service:

Figure 1. the lifecycle of the spelling check service.

To perform a spelling check, your application starts its implementation of the spelling checker. In an application, such as an activity or independent UI element, the client first requests a spelling check session from the server, and then uses this session to obtain spelling suggestions for the corresponding text. When the client terminates its operation, it will close its session for spelling check. If needed, your application can turn off the spelling check server at any time.

Implement a spelling checker Service

To use the framework of the spelling checker in your application, you must add a spelling check service component that contains the session object definition. You can also add an optional activity for control settings to your application. You must add an XML Metadata file describing the spelling check service and add the corresponding elements to the configuration file.

Class of the spelling checker

Use the following classes to define services and session objects:

Subclass of spellcheckerservice:

SpellcheckerserviceClass implements the interfaces of the service class and the spelling checker framework. In your subclass, you must implement the following methods:

Createsession ()

 
This factory method can return a spellcheckerservice. Session object to the client that wants to perform a spelling check.

For more information about implementation of this class, see spell.
Example checker Service Application

Spellcheckerservice. Session

 
This is an object provided by the spelling check service to the client. It is used to pass text to the spelling check tool and receive spelling suggestions. In this class, you must implement the following methods:

Oncreate ()


In the response to the createsession () method, the system will call this method. In this method, you can initialize the spellcheckerservice. Session object based on the current language environment.

onGetSentenceSuggestionsMultiple()


This method performs the actual spelling check. This method returns an array of sentencesuggestionsinfo objects, which contains the spelling suggestions for the passed sentences.

You can choose to implementonCancel()This method is used to cancel the spelling check. ongetsuggestions () is used to process the suggestion request for a word, ongetsuggestionsmultiple ()This API is used to batch process suggestion requests.

Note: You must use Asynchronous and thread-safe methods to fully implement spelling checks. A Spelling Checker can be called by different threads running on different cores at the same time.SpellCheckerServiceAnd spellcheckerservice. Session object will automatically complete this process.

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.