Overview

Applications like ebook readers, crosswords and other word games may leverage on dictionary language packs to retrieve words and their definitions.
If you are an Android developer, you may enable your Android application to retrieve the meaning of a word from dictionary language packs installed on the same device. An application can get word definitions from a language pack by using the procedure described in Content Provider Basics. A dictionary language pack implements the standard content provider capabilities.

The query may be performed using getContentResolver().query(uri, null, null, selectionArgs, null)

Both uri and selectionArgs are mandatory in the query() method. Note that the other parameters are ignored in the current implementation.

The following content uri allows your application to retrieve the definition of a word:

content://authority/dictionary

The following content uri may be used to perform a search with partial match:

content://authority/search_suggest_query

The provider's authority to be used in the content uri is:

livio.pack.lang.language.DictionaryProvider (language can be: it_IT, en_US, es_ES, fr_FR, de_DE, pt_BR)


Example: retrieve a word definition

Here is an example to retrieve italian definitions. Make sure to install the latest version of the italian language pack on your Android device.

General documentation about developing Android applications is available in Android Developers web site.

Let's start by defining some useful constants:

public static String AUTHORITY = "livio.pack.lang.it_IT.DictionaryProvider";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/dictionary");
public static final Uri CONTENT_URI3 = Uri.parse("content://" + AUTHORITY + "/"+ SearchManager.SUGGEST_URI_PATH_QUERY);

Now we do a simple query to retrieve the meaning of word 'pace':

String word = "pace";
Cursor cursor = getContentResolver().query(CONTENT_URI, null, null, new String[] {word}, null);
if ((cursor != null) && cursor.moveToFirst()) {
    int wIndex = cursor.getColumnIndexOrThrow(SearchManager.SUGGEST_COLUMN_TEXT_1);
    int dIndex = cursor.getColumnIndexOrThrow(SearchManager.SUGGEST_COLUMN_TEXT_2);
    Log.d("demo", "found word: "+ cursor.getString(wIndex)+", definition: "+ cursor.getString(dIndex));
} else {
    Log.d("demo", "missing word");
}

The execution of the above code may result in the following output in the logcat:

found word: pace, definition: <span class=head>sostantivo</span> (<i>f sing, plurale:</i> paci)<ol><li>stato di <a href="quiete">quiete</a></li><li><small>(<i>militare</i>)</small> situazione in cui i <a href="conflitti">conflitti</a> vengono gestiti senza ricorrere alla <a href="violenza">violenza</a></li></ol><span class=head>sillabazione</span><dl><dt>pà | ce</dt></dl><span class=head>etimologia</span><ul><li>dal <a href="latino">latino</a> <i>pax</i>, con la radice pak- presente anche in <a href="patto">patto</a></li></ul><span class=head>contrari</span><ul><li><a href="guerra">guerra</a></li></ul>

Note1: the output provided by the DictionaryProvider is an html fragment. The exact content may change in future releases, anyway the content is taylored to be rendered using a WebView object instance.

Note2: in case the given word is not found in the dictionary, the DictionaryProvider may return some suggestions.
Terms and conditions | Privacy policy