Overview

Applications, e.g. ebook readers and word games, may leverage on offline dictionaries to show the definitions of words.
You as Android developer may send a request from your Android application to the offline dictionary in order to retrieve the meaning of a word and show the definition to the user. The request has to be sent via a specific intent towards the offline dictionary.

Your application has to create an intent with an action equal to Intent.ACTION_SEARCH, using the package name of the target offline dictionary and adding the word to look for as extended data (SearchManager.QUERY) to the intent.

The following offline dictionaries are available in the Android Market:

LanguagePackage
English:livio.pack.lang.en_US
French:livio.pack.lang.fr_FR
Italian:livio.pack.lang.it_IT
Spanish:livio.pack.lang.es_ES
German:livio.pack.lang.de_DE
Portuguese:livio.pack.lang.pt_BR
Russian:livio.pack.lang.ru_RU

Example

Here is an example to show italian definitions. Make sure to install the latest version of the italian offline dictionary on your Android device.

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

Let's start by some useful imports:

import android.content.ActivityNotFoundException;
import android.app.Activity;
import android.app.SearchManager;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

Now we create an intent to retrieve the meaning of word 'pace':

String word = "pace";
Intent intent = new Intent(Intent.ACTION_SEARCH);
intent.setPackage("livio.pack.lang.it_IT");//you can use also livio.pack.lang.en_US, livio.pack.lang.es_ES, livio.pack.lang.de_DE, livio.pack.lang.pt_BR or livio.pack.lang.fr_FR
intent.putExtra(SearchManager.QUERY, word);
if (isIntentAvailable(this, intent)) // check if intent is available ?
    startActivity(intent);
else {ask the user to install latest version of offline dictionary}

Note that in case the intent is not available, you may insert a dialog suggesting the user to download the offline dictionary.
The method isIntentAvailable() is defined as follows:

public boolean isIntentAvailable(Context context, Intent intent) {
    List<ResolveInfo> lri = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return (lri != null) && (lri.size() > 0);
}



The offline dictionaries support a new intent from release 3.1 to start the CustomizeView activity. The user can enable/disable the optional parts of the word definition (e.g. synonyms and antonyms).

The new intent is named livio.intent.action.CUSTOMIZEVIEW.

In order to launch the Customise view activity, you can use the following code:

Intent intent = new Intent("livio.intent.action.CUSTOMIZEVIEW");
intent.setPackage("livio.pack.lang.it_IT");//you can use also livio.pack.lang.en_US, livio.pack.lang.es_ES, livio.pack.lang.de_DE, livio.pack.lang.pt_BR or livio.pack.lang.fr_FR
if (isIntentAvailable(this, intent))
    startActivity(intent);
else {ask the user to install latest version of offline dictionary}
Share Share on Facebook Share on Twitter Bookmark on Reddit Share via mail
Terms and conditions | Privacy policy